Updating native WPF controls to use the Actipro ThemeManager

As a side note before we dig in, the Ribbon product includes a number of built-in native styles for some native WPF controls that can be applied and auto-update with ThemeManager.CurrentTheme changes.  Check out the "Actipro Ribbon / Appearance Features / Other Control Styles" documentation topic for information on which native WPF controls are supported.

If you need to provide Actipro ThemeManager-based theme changing support for your own custom controls, or for other native WPF controls, use the information below to get started:

1) Look at the Shared Library's ThemedCustomControl demo in the Sample Browser.  This sample includes the full source code for implementing the mechanism we use in our products to switch control themes when ThemeManager.CurrentTheme changes.  In this demo we are providing seveal themes for a custom control called ThemedCustomControl.  But the same mechanism can be used even if no custom control is used and you are making themes for native controls.

2) SampleBrowserAssemblyThemedResourceDictionaryRegistrar tells the theme manager which themes are available and a related group name.  The group name is typically a product name, like Ribbon, but can be NativeControls, etc. if you are theming native controls.  We reference the group name in ThemedCustomControlBaseDictionary in this sample.

3) ThemedCustomControlBaseDictionary defines the group name to use, which could be something like "NativeControls".

4) ThemedCustomControlCommonDictionary is a good place to to define brush resources that will be shared, if you have any.  Otherwise you can leave it blank.

5) Then classes like ThemedCustomControlAeroNormalColorDictionary say where to get the related XAML file for the theme it represents.  One class is defined for each theme you'd like to support.  These classes are all referenced by the SampleBrowserAssemblyThemedResourceDictionaryRegistrar defined in #2.

6) The root Themes folder in the Sample Browser project then has a number of XAML files that kick in based on which system theme is loaded, so they should auto pull in other XAML files (like we do with /SampleBrowser;component/Themes/ThemedCustomControl/Classic.xaml)

7) The Themes/ThemedCustomControl folder has the XAML files that actually define themes.  So both the root Themes folder and those classes like ThemedCustomControlAeroNormalColorDictionary reference these.  To recap, the root Themes folder will activate the appropriate theme in this folder based on which system theme is set.  However if you set the ThemeManager.CurrentTheme property to manually switch a theme, the ThemeManager will manually load an alternate theme XAML file based on which theme you selected.

The XAML files in this folder are where you would want to create your styles for custom controls and/or native WPF controls.  For instance in these XAML files you could put code like:
<Style TargetType="Button">...</Style>

If you implement code similar to what is described above, you will have the proper theme auto-load up based on system theme.  But you'll also be able to set ThemeManager.CurrentTheme to change it.

Add Feedback