Show / Hide Table of Contents

Class ThemeManager

Allows overriding WPF theme resources.

Inheritance
Object
ThemeManager
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: PresentationTheme.Aero
Assembly: PresentationTheme.Aero.dll
Syntax
public sealed class ThemeManager
Remarks

WPF does not provide a way to replace the theme resources for system controls (i.e., those contained in the PresentationFramework assembly). Providing styles with proper type-keys in the resource inheritance tree or application-resources is not enough since those are skipped when looking up implicit base styles (i.e., for styles without explicit BasedOn). This class uses reflection to manipulate the internal dictionaries WPF uses to store theme resources.

Properties

| Improve this Doc View Source

IsOperational

Gets a value indicating whether the ThemeManager can manipulate internal WPF data structures. When false SetTheme(Assembly, IThemePolicy) and similar functions will always return false. This indicates that internal framework types may have changed.

Declaration
public static bool IsOperational { get; }
Property Value
Type Description
Boolean

Methods

| Improve this Doc View Source

ClearPresentationFrameworkTheme()

Clears the theme resources for the PresentationFramework assembly.

Declaration
public static bool ClearPresentationFrameworkTheme()
Returns
Type Description
Boolean

true on success; otherwise false.

Remarks

Unless explicitly overridden again (using SetTheme(Assembly, IThemePolicy) or similar), the next time a resource is looked up the default theme resources are loaded again.

| Improve this Doc View Source

ClearTheme(Assembly)

Clears the theme resources for the specified assembly.

Declaration
public static bool ClearTheme(Assembly assembly)
Parameters
Type Name Description
Assembly assembly

An Assembly containing WPF controls.

Returns
Type Description
Boolean

true on success; otherwise false.

Remarks

Unless explicitly overridden again (using SetTheme(Assembly, IThemePolicy) or similar), the next time a resource is looked up the default theme resources are loaded again.

Exceptions
Type Condition
ArgumentNullException

assembly is null.

| Improve this Doc View Source

Install()

Installs the theme manager.

Declaration
public static void Install()
Remarks

Hooks into the internal system resource loading machinery via splicing (i.e., patching code at runtime). This enables advanced theme resource resolution for all assemblies without proactively setting custom policies.

Exceptions
Type Condition
InvalidOperationException

The ThemeManager is not operational, i.e. IsOperational is false.

See Also
Uninstall()
| Improve this Doc View Source

SetPresentationFrameworkTheme(IThemePolicy)

Sets the theme resources for the PresentationFramework assembly.

Declaration
public static bool SetPresentationFrameworkTheme(IThemePolicy themePolicy)
Parameters
Type Name Description
IThemePolicy themePolicy

The theme policy to use.

Returns
Type Description
Boolean

true on success; otherwise false.

Exceptions
Type Condition
ArgumentNullException

themePolicy is null.

| Improve this Doc View Source

SetPresentationFrameworkTheme(Func<Uri>)

Sets the theme resources for the PresentationFramework assembly.

Declaration
public static bool SetPresentationFrameworkTheme(Func<Uri> themeUriProvider)
Parameters
Type Name Description
Func<Uri> themeUriProvider

A delegate providing the pack Uri to the location of the theme resource dictionary to use. The delegate will be invoked again to get an updated resource URI in case the system theme has changed. If the delegate returns null the default theme resources are used.

Returns
Type Description
Boolean

true on success; otherwise false.

Exceptions
Type Condition
ArgumentNullException

themeUriProvider is null.

| Improve this Doc View Source

SetPresentationFrameworkTheme(Uri)

Sets the theme resources for the PresentationFramework assembly.

Declaration
public static bool SetPresentationFrameworkTheme(Uri themeUri)
Parameters
Type Name Description
Uri themeUri

The pack Uri to the location of the theme resource dictionary to use.

Returns
Type Description
Boolean

true on success; otherwise false.

Exceptions
Type Condition
ArgumentNullException

themeUri is null.

| Improve this Doc View Source

SetTheme(Assembly, IThemePolicy)

Sets the theme resources for the specified assembly.

Declaration
public static bool SetTheme(Assembly assembly, IThemePolicy themePolicy)
Parameters
Type Name Description
Assembly assembly

An Assembly containing WPF controls.

IThemePolicy themePolicy

The theme policy to use.

Returns
Type Description
Boolean

true on success; otherwise false.

Exceptions
Type Condition
ArgumentNullException

assembly or themePolicy are null.

| Improve this Doc View Source

SetTheme(Assembly, Func<Uri>)

Sets the theme resources for the specified assembly.

Declaration
public static bool SetTheme(Assembly assembly, Func<Uri> themeUriProvider)
Parameters
Type Name Description
Assembly assembly

An Assembly containing WPF controls.

Func<Uri> themeUriProvider

A delegate providing the pack Uri to the location of the theme resource dictionary to use. The delegate will be invoked again to get an updated resource URI in case the system theme has changed. If the delegate returns null the default theme resources are used.

Returns
Type Description
Boolean

true on success; otherwise false.

Exceptions
Type Condition
ArgumentNullException

assembly or themeUriProvider are null.

| Improve this Doc View Source

Uninstall()

Uninstalls the theme manager.

Declaration
public static void Uninstall()
Exceptions
Type Condition
InvalidOperationException

The ThemeManager is not operational, i.e. IsOperational is false.

See Also
Install()

Events

| Improve this Doc View Source

ThemeChanged

Occurs following a system theme change event. Examples of theme change events are the activation of a theme, the deactivation of a theme, or a transition from one theme to another.

Declaration
public static event EventHandler ThemeChanged
Event Type
Type Description
EventHandler
Remarks

Corresponds the the native WM_THEMECHANGED message.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX