cansado2930
cansado2930

Reputation: 339

how to use textcolor on label of Xamarin forms?

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

Upvotes: 0

Views: 682

Answers (2)

Lucas Zhang
Lucas Zhang

Reputation: 18861

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>

Upvotes: 1

Guilherme Marques
Guilherme Marques

Reputation: 495

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

Upvotes: 0

Related Questions