question

10918804 avatar image
0 Votes"
10918804 asked JarvanZhang-MSFT commented

Apply Style for a specific control

Hi,

I am using below code to apply a style to a specific control on a specific pages but Xamarin is changing the style of all labels in my app.


 <Style x:Key="ExpanderHeaderLabel" TargetType="Label" ApplyToDerivedTypes="False">
     <Setter Property="TextColor" Value="{AppThemeBinding Light=#000000, Dark=#000000}" />
 </Style>


How can I fix this without having to have another style for all?


Thanks,
Jassim

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

How can I fix this without having to have another style for all?

The App style will not be applied for all the controls automatically. To consume a style, we need to reference the key for the Style property. Try the following code:

<Label Text="Testing for Resource Style"/>
<Label Text="Testing for Resource Style" Style="{StaticResource ExpanderHeaderLabel}"/>

Check the doc: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/introduction#create-a-style

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@10918804 May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.

0 Votes 0 ·