Theme Resources

To handle the light versus dark app themes and high contrast user theme, ResourceDictionary has a ThemeDictionaries property that can contain separate ResourceDictionarys, one for each possible theme. The correct one automatically gets merged into the host ResourceDictionary based on the current theme.

These theme dictionaries can contain any resource, such as complete Styles, but it’s more common for them to contain specific Brushes referenced by a single theme-independent Style. The following XAML demonstrates:

<Page ...>   <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">     <StackPanel Margin="20" Orientation="Horizontal">       <StackPanel.Resources>         <ResourceDictionary ...

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.