Skip to main content

Applying Themes

  • 2 minutes to read

Note

The WPF Theme Editor does not support the DevExpress WPF Controls 18.2 or later. Use the WPF Theme Designer tool instead.

This topic describes how to apply a newly created theme to a WPF application.

Note that after you have modified and built a predefined theme, the changes are applied automatically to all applications that use this theme, and you do not need to perform actions described in this topic. To learn more, see Creating and Opening Themes.

To apply a theme to an application, follow the steps below.

  1. Add a reference to the theme assembly. You can find the assembly in the %ThemeDirectory%\Bin directory.

    GettingStarted_AddReference

  2. Create a Theme instance using the Theme constructor overload that takes five arguments: theme name (the one you have specified when creating the theme), full name (includes namespace and version number), theme category and small theme glyph and large theme glyph inherited from the base theme as shown below. The last three parameters are optional.

    Theme customTheme = new Theme("CustomTheme", "DevExpress.Xpf.Themes.CustomTheme.v18.1", "Custom Themes",
                    new Uri("pack://application:,,,/DevExpress.Xpf.Core.v18.1;component/Themes/Images/Seven_16x16.png"),
                    new Uri("pack://application:,,,/DevExpress.Xpf.Core.v18.1;component/Themes/Images/Seven_48x48.png"));
    

    Note

    The default theme glyphs are located in the DevExpress.Xpf.Core.v18.1.dll assembly. You can specify custom glyphs instead.

  3. Specify the assembly name (matches the theme full name by default) using the Theme.AssemblyName property.
  4. Use the static Theme.RegisterTheme method to register the new theme in ThemeManager.
  5. Finally, apply the theme using the ThemeManager.SetTheme method.

You can add the resulting code to the MainWindow constructor as shown in the sample below.

using DevExpress.Xpf.Core;
//...
public partial class MainWindow : Window {
    public MainWindow() {
        Theme customTheme = new Theme("CustomTheme", "DevExpress.Xpf.Themes.CustomTheme.v18.1", "Custom Themes",
                new Uri("pack://application:,,,/DevExpress.Xpf.Core.v18.1;component/Themes/Images/Seven_16x16.png"),
                new Uri("pack://application:,,,/DevExpress.Xpf.Core.v18.1;component/Themes/Images/Seven_48x48.png"));
        customTheme.AssemblyName = "DevExpress.Xpf.Themes.CustomTheme.v18.1";
        Theme.RegisterTheme(customTheme);
        ThemeManager.SetTheme(this, customTheme);
        InitializeComponent();
    }
}