In This Article

ThemeManager Class

Manages the themes used for various products.

public static class ThemeManager
Inheritance:
object object

Properties

AreNativeThemesEnabled

Gets or sets a value indicating whether the implicit native styles should be loaded into the application resources.

public static bool AreNativeThemesEnabled { get; set; }

Property Value

bool:

true if the implicit native styles should be loaded into the application resources; otherwise, false.

CurrentTheme

Gets or sets the name of the current default application-wide theme.

public static string CurrentTheme { get; set; }

Property Value

string:

The name of the current default application-wide theme (e.g. Light, Dark, etc.).

Remarks

The ThemeNames enumeration contains a number of commonly-used theme names, whose string values can be set to this property.

HasAutomaticThemes

Gets whether there are any automatic themes currently registered via RegisterAutomaticThemes(string, string, string).

public static bool HasAutomaticThemes { get; }

Property Value

bool:

true if there are any automatic themes currently registered; otherwise, false.

IsAnimationSupported

Gets whether animation is supported by the system, also validating that IsGraphicsHardwareAccelerationSupported is true.

public static bool IsAnimationSupported { get; }

Property Value

bool:

true if animation is supported by the system, also validating that IsGraphicsHardwareAccelerationSupported is true; otherwise, false.

Remarks

By default, this property examines the SystemParameters.ClientAreaAnimation and RenderCapability.Tier properties to determine if animation is supported, but the IsAnimationSupportedOverride property can be set to an explicit value to override the detected capability.

IsAnimationSupportedOverride

Gets or sets an override for the IsAnimationSupported property.

public static bool? IsAnimationSupportedOverride { get; set; }

Property Value

bool?:

null to use system settings and hardware capabilities to determine if animation is supported (default setting), true to allow animation even if the system and hardware do not support it, or false to disable animation even if the system and hardware support it.

See Also

IsGraphicsHardwareAccelerationSupported

Gets whether graphics hardware acceleration is available on the system.

public static bool IsGraphicsHardwareAccelerationSupported { get; }

Property Value

bool:

true if graphics hardware acceleration is available on the system; otherwise, false.

Remarks

This property examines the RenderCapability.Tier property.

RegisteredCatalogs

Gets the catalogs registered with the theme manager.

public static IEnumerable<ThemeCatalogBase> RegisteredCatalogs { get; }

Property Value

IEnumerable<ThemeCatalogBase>:

The catalogs registered with the theme manager.

RegisteredThemeDefinitions

Gets the ThemeDefinition instances registered with the theme manager.

public static IEnumerable<ThemeDefinition> RegisteredThemeDefinitions { get; }

Property Value

IEnumerable<ThemeDefinition>:

The ThemeDefinition instances registered with the theme manager.

SystemApplicationMode

Gets a SystemApplicationMode indicating the theme that applications should use, as specified by the system settings.

public static SystemApplicationMode SystemApplicationMode { get; }

Property Value

SystemApplicationMode:

A SystemApplicationMode indicating the theme that applications should use, as specified by the system settings.

Methods

ApplyTheme()

Applies or updates the application-wide theme.

public static void ApplyTheme()

ApplyTheme(FrameworkElement)

Applies or updates the theme for the specified element.

public static void ApplyTheme(FrameworkElement element)
Parameter Type Description
element FrameworkElement

BeginUpdate()

Prevents the theme manager from updating the theme until the EndUpdate() method is called.

public static void BeginUpdate()

CreateDefaultThemeDefinition(string)

Creates a new default ThemeDefinition for the specified predefined known theme.

public static ThemeDefinition CreateDefaultThemeDefinition(string themeName)
Parameter Type Description
themeName string

The theme name.

Returns

ThemeDefinition:

The new default ThemeDefinition that was created.

Remarks

This method should be called with one of the values from the ThemeNames class.

EndUpdate()

Updates the current theme based on changes since the BeginUpdate() method was called.

public static void EndUpdate()

GetAreNativeThemesEnabled(DependencyObject)

Gets the value of the AreNativeThemesEnabled attached property for the specified object.

public static bool GetAreNativeThemesEnabled(DependencyObject obj)
Parameter Type Description
obj DependencyObject

The object from which the property value is read.

Returns

bool:

The object's value.

GetDesignModeAreNativeThemesEnabled(DependencyObject)

Gets the value of the DesignModeAreNativeThemesEnabled attached property for the specified object.

public static bool GetDesignModeAreNativeThemesEnabled(DependencyObject obj)
Parameter Type Description
obj DependencyObject

The object from which the property value is read.

Returns

bool:

The object's value.

GetDesignModeTheme(DependencyObject)

Gets the value of the DesignModeTheme attached property for the specified object.

public static string GetDesignModeTheme(DependencyObject obj)
Parameter Type Description
obj DependencyObject

The object from which the property value is read.

Returns

string:

The object's value.

GetIsAnimationEnabled(DependencyObject)

Returns whether animation is enabled on the specified visual, also verifying that system animation is supported.

public static bool GetIsAnimationEnabled(DependencyObject visual)
Parameter Type Description
visual DependencyObject

The System.Windows.DependencyObject to examine.

Returns

bool:

true if animation is enabled on the specified visual; otherwise, false.

Remarks

This method examines the visual to see if its attached ThemeProperties.IsAnimationEnabled property is true, and that the visual is currently loaded in UI, if it is a FrameworkElement. Finally the IsAnimationSupported property is checked to ensure the system supports animation.

GetTheme(DependencyObject)

Gets the value of the Theme attached property for the specified object.

public static string GetTheme(DependencyObject obj)
Parameter Type Description
obj DependencyObject

The object from which the property value is read.

Returns

string:

The object's value.

GetThemeDefinition(string)

Returns the registered or default ThemeDefinition for the specified theme.

public static ThemeDefinition GetThemeDefinition(string themeName)
Parameter Type Description
themeName string

The theme name.

Returns

ThemeDefinition:

The registered or default ThemeDefinition for the specified theme.

Remarks

If a ThemeDefinition was registered via RegisterThemeDefinition(ThemeDefinition) for the theme name, it will be returned. Otherwise, the CreateDefaultThemeDefinition(string) method is called and a new ThemeDefinition will be returned that is based on any predefined known themes.

IsDarkTheme(string)

Returns whether the specified theme is a dark theme.

public static bool IsDarkTheme(string themeName)
Parameter Type Description
themeName string

The theme name.

Returns

bool:

true if the specified theme is a dark theme; otherwise, false.

Remarks

If a ThemeDefinition was registered via RegisterThemeDefinition(ThemeDefinition) for the theme name, its intent will be examined. If no matching registered theme definition is found, predefined known themes will be examined. Otherwise, this method will return false.

IsHighContrastTheme(string)

Returns whether the specified theme is a high-contrast theme.

public static bool IsHighContrastTheme(string themeName)
Parameter Type Description
themeName string

The theme name.

Returns

bool:

true if the specified theme is a high-contrast theme; otherwise, false.

Remarks

If a ThemeDefinition was registered via RegisterThemeDefinition(ThemeDefinition) for the theme name, its intent will be examined. If no matching registered theme definition is found, predefined known themes will be examined. Otherwise, this method will return false.

IsThemeSupported(string)

Returns whether the specified theme is currently supported.

public static bool IsThemeSupported(string themeName)
Parameter Type Description
themeName string

The theme name.

Returns

bool:

true if the specified theme is currently supported, otherwise, false.

Remarks

A theme is supported if it is a predefined theme, or is a theme that has been registered with the RegisterThemeDefinition(ThemeDefinition) method.

RegisterAutomaticThemes(string, string, string)

Registers the theme names that should be automatically set to CurrentTheme based on SystemApplicationMode and changes to that property.

public static void RegisterAutomaticThemes(string lightThemeName, string darkThemeName, string highContrastThemeName)
Parameter Type Description
lightThemeName string

The theme name to use when system settings indicate applications should use a light theme.

darkThemeName string

The theme name to use when system settings indicate applications should use a dark theme.

highContrastThemeName string

The theme name to use when system settings indicate a high contrast system theme is active.

Remarks

The theme names passed into this method should be names of themes registered via RegisterThemeDefinition(ThemeDefinition).

A null reference may be passed into any of this method's parameters to prevent automatic CurrentTheme changes when the related SystemApplicationMode changes are detected.

For instance, if you only wish to handle the system settings' light/dark application setting, but never want to support a high contrast theme, call this method specifying registered theme names for the first two parameters, but pass a null reference to the highContrastThemeName parameter.

RegisterThemeCatalog(ThemeCatalogBase)

Registers a theme catalog.

public static void RegisterThemeCatalog(ThemeCatalogBase catalog)
Parameter Type Description
catalog ThemeCatalogBase

The ThemeCatalogBase to register.

RegisterThemeCatalog(object, ThemeCatalogBase)

Registers a theme catalog using the specified key.

public static void RegisterThemeCatalog(object key, ThemeCatalogBase catalog)
Parameter Type Description
key object

A unique key associated with the specified catalog.

catalog ThemeCatalogBase

The ThemeCatalogBase to register.

RegisterThemeDefinition(ThemeDefinition)

Registers a ThemeDefinition instance that can be used for theme asset generation when the CurrentTheme property is set to the definition' Name.

public static void RegisterThemeDefinition(ThemeDefinition definition)
Parameter Type Description
definition ThemeDefinition

The ThemeDefinition to register.

SetAreNativeThemesEnabled(DependencyObject, bool)

Sets the value of the AreNativeThemesEnabled attached property to the specified object.

public static void SetAreNativeThemesEnabled(DependencyObject obj, bool value)
Parameter Type Description
obj DependencyObject

The object to which the attached property is written.

value bool

The value to set.

SetDesignModeAreNativeThemesEnabled(DependencyObject, bool)

Sets the value of the DesignModeAreNativeThemesEnabled attached property to the specified object.

public static void SetDesignModeAreNativeThemesEnabled(DependencyObject obj, bool value)
Parameter Type Description
obj DependencyObject

The object to which the attached property is written.

value bool

The value to set.

SetDesignModeTheme(DependencyObject, string)

Sets the value of the DesignModeTheme attached property to the specified object.

public static void SetDesignModeTheme(DependencyObject obj, string value)
Parameter Type Description
obj DependencyObject

The object to which the attached property is written.

value string

The value to set.

SetTheme(DependencyObject, string)

Sets the value of the Theme attached property to the specified object.

public static void SetTheme(DependencyObject obj, string value)
Parameter Type Description
obj DependencyObject

The object to which the attached property is written.

value string

The value to set.

UnregisterAutomaticThemes()

Unregisters all automatic theme changes from a prior call to RegisterAutomaticThemes(string, string, string).

public static void UnregisterAutomaticThemes()

UnregisterThemeCatalog(ThemeCatalogBase)

Unregisters a theme catalog.

public static void UnregisterThemeCatalog(ThemeCatalogBase catalog)
Parameter Type Description
catalog ThemeCatalogBase

The ThemeCatalogBase to unregister.

UnregisterThemeCatalog(object)

Unregisters a theme catalog using the specified key.

public static void UnregisterThemeCatalog(object key)
Parameter Type Description
key object

A unique key associated with the specified catalog.

UnregisterThemeDefinition(string)

Unregisters a ThemeDefinition instance using the specified theme name.

public static void UnregisterThemeDefinition(string themeName)
Parameter Type Description
themeName string

The theme name for which to unregister ThemeDefinition.

Events

CurrentThemeChanged

Occurs after the CurrentTheme property has changed.

public static event EventHandler CurrentThemeChanged

Event Type

EventHandler

SystemApplicationModeChanged

Occurs when the SystemApplicationMode property is changed.

public static event EventHandler SystemApplicationModeChanged

Event Type

EventHandler

Fields

AreNativeThemesEnabledProperty

Identifies the AreNativeThemesEnabled dependency property. This field is read-only.

public static readonly DependencyProperty AreNativeThemesEnabledProperty

DesignModeAreNativeThemesEnabledProperty

Identifies the DesignModeAreNativeThemesEnabled dependency property. This field is read-only.

public static readonly DependencyProperty DesignModeAreNativeThemesEnabledProperty

DesignModeThemeProperty

Identifies the DesignModeTheme dependency property. This field is read-only.

public static readonly DependencyProperty DesignModeThemeProperty

ThemeProperty

Identifies the Theme dependency property. This field is read-only.

public static readonly DependencyProperty ThemeProperty

Inherited Members