Skip to content

Common Tasks

Yimeng Wu edited this page Oct 21, 2019 · 19 revisions

Set the theme and accent color of the app

The default theme and accent color are as follows:

  • For systems running Windows 10, the system accent color is used. If the Windows version supports the "choose your default app mode" setting, this setting is used; otherwise, the light theme is used.
  • For systems running an earlier version of Windows, the light theme and the color #0078D7 (default blue) are used. To override the default settings, set properties on the ThemeResources class in App.xaml. For example:
<ui:ThemeResources RequestedTheme="Dark" AccentColor="Red" />

Values set this way are applied at both design time and runtime. However, changing them after the app has started takes no effect, nor do they support data binding. To change the theme and accent color at runtime, set properties on the ThemeManager class. For example:

private void Button_Click(object sender, RoutedEventArgs e)
{
    ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
    ThemeManager.Current.AccentColor = Colors.Red;
}

Values set on ThemeManager will take precedence over values set on ThemeResources at runtime.

Override the theme at element level

Set the ThemeManager.RequestedTheme attached property on any FrameworkElement. For example:

<Border
    Background="{DynamicResource SystemControlBackgroundAltHighBrush}"
    Padding="12"
    ui:ThemeManager.RequestedTheme="Dark">
    <Button Content="Dark theme button" />
</Border>

Currently this feature doesn't work correctly at design time.

Clone this wiki locally