简体   繁体   中英

How can I set a label color to that of a dynamic resource in C#?

Here's the code that I have:

grid.Children.Add(new Label
{
   Text = "00",
   VerticalOptions = LayoutOptions.Center,
   HorizontalOptions = LayoutOptions.Center,
   TextColor = " {DynamicResource PageBackgroundColor}"
});

But it does not accept that format for the setting of Dynamic resource.

That is happening because you are using the wrong syntax to do it, try something like this:

TextColor = (Color) App.Current.Resources["PageBackgroundColor"];

In case there is a query, please revert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM