如何在 Xamarin 表单的标签上使用 textcolor? [英] how to use textcolor on label of Xamarin forms?
问题描述
这个问题很简单也很奇怪……我想这可能是一个错误……去吧.我有标签,我尝试使用静态资源的键设置背景颜色,其中它具有颜色的十六进制值.它运作良好.然后,我想在文本而不是背景上使用这种颜色,所以我将它从 Xaml 的 brackgroundcolor 属性更改为 TextColor 属性.它显示为白色而不是自定义颜色.我应该做些什么来设置我的自定义颜色而不是白色吗?
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?
我附上了资源示例和标签的 xaml 行:
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" />
该应用适用于 Android,版本为 3.6.0.220655.
The app is for Android, and version 3.6.0.220655.
谢谢
推荐答案
尝试删除文件夹 bin
和 obj
.然后清理并重建您的项目.我不不要认为您的代码有任何问题.因为我使用以下代码并且它在 Android 和 iOS 上都可以正常工作.
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>
这篇关于如何在 Xamarin 表单的标签上使用 textcolor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!