Class ThemeManager
Allows overriding WPF theme resources.
Inherited Members
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 SourceIsOperational
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 SourceClearPresentationFrameworkTheme()
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.
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 |
|
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
| Improve this Doc View SourceSetPresentationFrameworkTheme(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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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
Events
| Improve this Doc View SourceThemeChanged
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.