FrameworkElement.RequestedTheme property

Applies to Windows and Windows Phone

Gets or sets the UI theme that is used by the UIElement (and its child elements) for resource determination. The UI theme you specify with RequestedTheme can override the app-level RequestedTheme.

Syntax


public ElementTheme RequestedTheme { get; set; }


<uiElement RequestedTheme="elementThemeMemberName" .../>

Property value

Type: ElementTheme

A value of the enumeration, for example Light.

Remarks

Changing the RequestedTheme value is effectively changing the resource lookup behavior for the element's default template. If you change the value to Light then the template uses the values from the ResourceDictionary that is keyed as "Light" in the ThemeDictionaries collection. Setting the UI theme differently from the app's theme is often appropriate for floating controls such as menus and flyouts.

You can change the value of the RequestedTheme property for any given element at run-time. That's in contrast to the Application.RequestedTheme property, which throws an exception if you try to set it while the app's running.

The RequestedTheme value you set on a FrameworkElement will inherit to any elements that are nested within the element where RequestedTheme is set, but that inheritance can be overridden by explicitly setting RequestedTheme again. For example, in this XAML example, the parent StackPanel sets the theme to Light, and that value inherits to the first TextBlock child element, but not to the second TextBlock because it's setting the value to Dark instead.


<StackPanel RequestedTheme="Light">
  <TextBlock>Text using light theme.</TextBlock>
  <TextBlock RequestedTheme="Dark">Text using dark theme.</TextBlock>
</StackPanel>

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.

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.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

FrameworkElement
Application.RequestedTheme
XAML requested theme sample
ThemeResource markup extension

 

 

Show:
© 2014 Microsoft