Setting a colour from a StaticResource in C#

If you want to use a {StaticResource} colour for Foreground text then there are examples aplenty on how to do this in XAML. However it did take me a while to find out how to do this if I wanted to set it in code i.e. C#

So within a TextBlock construct within XAML you might say for a TextBlock called Label_CurrentClient:

Foreground="{StaticResource SystemChromeMediumLowColor}"

In C# you would say:

Label_CurrentClient.Foreground = new SolidColorBrush((Windows.UI.Color)Application.Current.Resources["SystemChromeMediumLowColor"]);

Comments

Popular posts from this blog

ParallaxView suddenly no longer supports direct content

Resource Strings - UWP vs net 5