Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
User interface Xamarin Forms-Can';t使用TextColor属性替代样式_User Interface_Xamarin_Overriding_Xamarin.forms - Fatal编程技术网

User interface Xamarin Forms-Can';t使用TextColor属性替代样式

User interface Xamarin Forms-Can';t使用TextColor属性替代样式,user-interface,xamarin,overriding,xamarin.forms,User Interface,Xamarin,Overriding,Xamarin.forms,我的标签样式定义如下: var myLabelStyle = new Style(typeof(Label)) { Setters = { new Setter { Property = Label.TextColorProperty, Value = Color.Blue }, new Setter { Property = Label.FontSizeProperty, Value = 30 } } }; 然后我有一个这样定义的标签:

我的标签样式定义如下:

var myLabelStyle = new Style(typeof(Label))
{
    Setters =
    {
        new Setter { Property = Label.TextColorProperty, Value = Color.Blue },
        new Setter { Property = Label.FontSizeProperty, Value = 30 }
    }
};
然后我有一个这样定义的标签:

var myLabel = new Label
{
    Text = "My Label",
    Style = myLabelStyle,
    TextColor = Color.Red
};
那标签的颜色不应该是红色的吗?嗯,是蓝色的

根据直觉,我应该能够覆盖样式中定义的任何给定属性(参见屏幕截图后的一句话)


给出了什么?

我看不出您的代码有任何错误:,它在本例中正常工作:

var myLabelStyle = new Style(typeof(Label))
{
    Setters =
    {
    new Setter { Property = Label.TextColorProperty, Value = Color.Blue },
    new Setter { Property = Label.FontSizeProperty, Value = 30 }
    }
};
var myLabelRed = new Label
{
    Text = "My Red Label",
    Style = myLabelStyle,
    TextColor = Color.Red
};
var myLabelBlue = new Label
{
    Text = "My Blue Label",
    Style = myLabelStyle,
};
var content = new ContentPage
{
    Content = new StackLayout
    {
        Children = {
            myLabelRed,
            myLabelBlue
        }
    }
};
iOS:

安卓:


这似乎是一个Xamarin Forms bug在2.0.0.6482版(按预期工作)和2.2.0.31版(坏了!不按预期工作)之间引入的缺陷。

如果我创建了一个新项目,它会按预期工作,但在我所在的项目中不工作。如果我将代码直接放在App.cs中,然后调用
MainPage=newcontentpage{Content=newstacklayout{Children={myLabel}}
,它在我当前的项目中确实有效。但是,如果我创建一个从ContentPage继承的新MyPage.cs,将代码放在其中,然后在App.cs中调用
MainPage=new MyPage()
,它就不起作用了。我正在使用Fody.PropertyChanged,我开始怀疑这是否是问题所在。这是b/c新项目使用的是一个Xamarin表单的版本,在这个版本中它没有被破坏。我从未找到过一个,除了恢复到旧版本的Xamarin表单(除非他们在新版本中修复)。我被迫创建了一堆额外的样式。谢谢你回来。