uwp Theme Resources

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • C# : Application.Current.Resources["yourColorKey"]
  • Xaml : {ThemeResource yourColorKey}

Parameters

ParameterPurpose
yourColorKeyA key you give to get a Color object back. It differs between C# and Xaml

Remarks

UWP allows you to take full control of the advantages of Windows 10. Some of these advantages are graphical, as the Accent color or Dark/Light themes.

To prepare your app to be compatible with these feature, a bunch of premade colors have been implemented in UWP to change with the Accent color of the OS the program runs on, or with the theme choice of the user.

There are two "ways" of doing this :

  • Diretly in Xaml, using the Color = {ThemeResource x} Attribute (or whatever attribute that takes a Brushas value, like BorderBrush, Background, etc.)

  • In C# Code Behind, by Searching for the color in the Resource directory of the current app. This gives a Color object, so if you want to put it in the Color property of an object you referenced from your Xaml, you'll need to make a new brush like this :

new SolidColorBrush(Application.Current.Resources["yourColorKey"])

For a reference of color keys in c#, please consult :

https://msdn.microsoft.com/windows/uwp/controls-and-patterns/xaml-theme-resources



Got any uwp Question?