Application.RequestedTheme property

Applies to Windows and Windows Phone

Gets or sets a value that determines the light-dark preference for the overall theme of an app.

Syntax


public ApplicationTheme RequestedTheme { get; set; }


<application RequestedTheme="applicationThemeMemberName" .../>

Property value

Type: ApplicationTheme

A value of the enumeration.

Remarks

There are two built in themes: "Light" and "Dark". By default your app runs using the "Dark" theme (in the themeresources.xaml file, the key name for the "Dark" resources is "Default"). You can set the app's RequestedTheme property to specify which theme is used.

The theme can only be set when the app is started, not while it’s running. Attempting to set RequestedTheme while the app is running throws an exception (NotSupportedException for Microsoft .NET code). If you give the user an option to pick a theme that's part of app UI, you must save the setting in the app data and apply it when the app is restarted.

There is also a "HighContrast" theme that uses system values, but apps and app code use a different technique for switching the app to high contrast. The RequestedTheme property is ignored if the user is running in high contrast mode. See Supporting high contrast themes and XAML high contrast style sample.

Although the app can't switch the themes at run-time, the user can (starting with Windows 8.1). For example, a user might enable a high-contrast theme while your app is running, by using the Alt+Shift+PrtScn key shortcut. If this happens, the XAML resource system will recalculate the resource values for any ThemeResource usage. Theme-appropriate resources such as colors and brushes then use values appropriate for the current theme, even though it wasn't the app that requested that theme originally.

An app can change specific theme values at run-time after Application.RequestedTheme is applied, if it uses the FrameworkElement.RequestedTheme property and sets values on specific elements in the UI.

The resources that are theme-specific are typically defined in a separate resource dictionary in XAML. This resource dictionary comes from the ThemeDictionaries property of the primary ResourceDictionary that is used for control templates. The default system resource dictionary for theme-specific resources is named ThemeResources.xaml. Find this file under the path \include\winrt\xaml\design in your Windows Software Development Kit (SDK) for Windows 8 installation location.

Note  On Windows, setting RequestedTheme to ElementTheme.Default will always result in "Dark" being the theme. On Windows Phone, using the ElementTheme.Default value will result in a query for the system theme, as set by the user.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

Application
FrameworkElement.RequestedTheme
XAML requested theme sample
Supporting high-contrast themes

 

 

Show:
© 2014 Microsoft