问题
The question is very easy and strange… I'm thinking that it may be a bug... Go it. I have Label where I try to set the background color with key of static resource where it has the Hex value of color. It works good. then, I want to use this color on text instead of background so I have changed it from brackgroundcolor property of Xaml to TextColor property. And it is showed with white color instead the custom color. Should I have to do something in order to set the my custom color instead white?
I have attached sample of resource and the xaml line of Label:
<ResourceDictionary>
<Color x:Key="Fondo">#38aae1</Color>
</ResourceDictionary>
…
<Label Text="sample" FontSize="15" TextColor="{StaticResource Fondo}" FontAttributes="Bold" />
The app is for Android, and version 3.6.0.220655.
Thank you
回答1:
Try to delete the folder bin and obj .Then clean and rebuild your project.I don't think there's anything wrong with your code.Because I use the following code and it works fine both on Android and iOS.
<StackLayout>
<StackLayout.Resources>
<ResourceDictionary>
<Color x:Key="Fondo">#38aae1</Color>
</ResourceDictionary>
</StackLayout.Resources>
<Label Text="sample" FontSize="15" TextColor="{StaticResource Fondo}" FontAttributes="Bold" />
</StackLayout>
回答2:
try this
<ResourceDictionary>
<Color x:Key="Fondo">#38AAE1</Color>
</ResourceDictionary>
…
<Label Text="sample" FontSize="15" TextColor="{StaticResource Fondo}" FontAttributes="Bold" />
Maybe the Background Color value need to be uppercase or need (")between the text.
Regards
来源:https://stackoverflow.com/questions/55144835/how-to-use-textcolor-on-label-of-xamarin-forms