Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ContentPage中背景的Xamarin Xaml样式_C#_Xaml_Xamarin - Fatal编程技术网

C# ContentPage中背景的Xamarin Xaml样式

C# ContentPage中背景的Xamarin Xaml样式,c#,xaml,xamarin,C#,Xaml,Xamarin,最近在Xamarin工作,如果我尝试为ContentPage设置样式,似乎什么都不会发生 App.Xaml的ResourceDictionary中的Xaml: <Style TargetType="ContentPage"> <Setter Property="BackgroundColor" Value="#f8f8f8"/> </Style> 我知道正在阅读app.xaml样式。我有一个按钮样式,已经在全球应用。但我似乎无法影响Content

最近在Xamarin工作,如果我尝试为
ContentPage
设置样式,似乎什么都不会发生

App.Xaml的ResourceDictionary中的Xaml:

<Style TargetType="ContentPage">
    <Setter Property="BackgroundColor" Value="#f8f8f8"/>
</Style>

我知道正在阅读app.xaml样式。我有一个按钮样式,已经在全球应用。但我似乎无法影响
ContentPage
上的任何更改。没有报告任何错误

如何全局设置背景色


我读到这可能是一个bug,但那是一年前的事了。如果它仍然是一个bug,有解决方法吗?

遵循@Tomasz Kowalczyk使用示例xaml的提示:

在app.xaml ResourceDictionary中,输入以下样式:

<Style x:Key="defaultPageStyle" TargetType="ContentPage">
   <Setter Property="BackgroundColor" Value="#f8f8f8"/>
</Style>
然后在每个xaml.cs类中将其结合在一起:

namespace MyNamespace
{
    public partial class MyXamlPage: BaseContentPage
和.xaml文件

<local:BaseContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:MyNamespace;assembly=MyNamespace"
         x:Class="MyNamespace.MyXamlPage"

以下
App.xaml
中的代码适用于我:

<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
   <Setter Property="BackgroundColor" Value="Lime" />
</Style>

注:

  • 您不应该在
    样式中使用属性
    x:Key
  • 您应该添加
    ApplyToDerivedTypes=“True”

我在

找到了解决方案,请阅读这篇文章,它可能很有用,有一个bug与此相关,还有一些解决方法我也尝试过,但我很难弄清楚我主页上的xaml会是什么样子like@TomaszKowalczyk,谢谢你的帮助。你给我指出了正确的道路。那么也许投票支持我的评论?;)@TomaszKowalczyk,我会做得更好,因为投票没有任何作用。在C#?@tmighty中会是什么样子,我不明白。此解决方案在c#和xaml中都有。
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
   <Setter Property="BackgroundColor" Value="Lime" />
</Style>