Skip to main content
A newer version of this page is available. .

Palettes

  • 4 minutes to read

Palettes allow you to integrate corporate colors into your application and expand variety of themes. You can create a custom palette or use the predefined palettes.

Theme Palettes

The Palette is a list of named colors. Each named color has the ColorName and Color values. You can use the ColorName to assign the Color to any number of UI elements:

WPF Themes - Palette Mechanism Scheme

WPF Themes - Palette Mechanism Example

The following DevExpress WPF Themes contain palettes:

Theme Family Themes
Office 2019 Black, Colorful, Dark Gray, White
Office 2016 SE Black, Colorful, Dark Gray, White
Visual Studio 2017 Blue, Dark, Light

Predefined Palettes

Palette Themes include the following predefined palettes:

WPF Themes - Predefined Palettes

Apply a Palette in Code

Note

The application does not unload the loaded theme assemblies when you switch themes.

  1. Reference the Mono.cecil NuGet package in your project.
  2. Call the Theme.RegisterPredefinedPaletteThemes method to enable predefined palettes.
  3. Set the ApplicationThemeHelper.ApplicationThemeName property to a combination of a predefined palette name + a base theme name.

    Theme.RegisterPredefinedPaletteThemes();
    ApplicationThemeHelper.ApplicationThemeName = PredefinedThemePalettes.RedWine.Name + Theme.Office2019White.Name;
    

The code sample above enables all available palettes for the current theme. To enable and apply a single palette:

  1. Reference the Mono.cecil NuGet package in your project.
  2. Pass the palette and a base theme to the Theme.CreateTheme method to create a new theme.
  3. Pass the theme to the Theme.RegisterTheme method.
  4. Set the ApplicationThemeHelper.ApplicationThemeName property to the theme‘s name.

    var palettetheme = Theme.CreateTheme(PredefinedThemePalettes.RedWine, Theme.Office2019White); 
    Theme.RegisterTheme(palettetheme); 
    ApplicationThemeHelper.ApplicationThemeName = palettetheme.Name;
    

You can display predefined palettes in the Ribbon Gallery to allow users to select a palette and apply it to the current theme:

WPF Themes - Palettes in Ribbon Gallery

  1. Reference the DevExpress.Mvvm.v19.1.dll assembly.
  2. Call the Theme.RegisterPredefinedPaletteThemes method at application startup to enable these palettes:

    public partial class App : Application {
        protected override void OnStartup(StartupEventArgs e) {
            Theme.RegisterPredefinedPaletteThemes();
            base.OnStartup(e);
        }
    }
    
  3. Attach the RibbonGalleryItemThemePaletteSelectorBehavior to a RibbonGalleryBarItem:

    <dxr:RibbonGalleryBarItem ... >
        <dxmvvm:Interaction.Behaviors>
            <dxr:RibbonGalleryItemThemePaletteSelectorBehavior />
        </dxmvvm:Interaction.Behaviors>
    </dxr:RibbonGalleryBarItem>
    

Custom Palettes

Refer to the Theme Designer’s Edit Palette Colors topic for more information on how to create a custom theme palette.

You can export your palette in the following ways:

Edit Palettes in Code

Note

The application does not unload the loaded theme assemblies when you switch themes.

To apply a custom palette to an application:

  1. Reference the Mono.cecil NuGet package in your project.
  2. Create a new ThemePalette instance:

    var custompalette = new ThemePalette("CustomPalette");
    

    … or create a new ThemePalette instance based on a predefined palette. In this case, the new palette inherits a predefined palette’s colors:

    var custompalette = new ThemePalette("CustomPalette", PredefinedThemePalettes.RedWine);    
    
  3. Use the ThemePalette.SetColor method to specify new colors:

    custompalette.SetColor("Foreground", (Color)ColorConverter.ConvertFromString("#FFFF7200"));
    custompalette.SetColor("Backstage.Focused", Colors.White);    
    
  1. Pass the palette and a theme with palette support to the Theme.CreateTheme method to create a new theme:

    var customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE);    
    
  2. Pass the theme to the Theme.RegisterTheme method and set the ApplicationThemeHelper.ApplicationThemeName to the theme’s name to apply the theme to an application:

    Theme.RegisterTheme(customtheme);
    ApplicationThemeHelper.ApplicationThemeName = customtheme.Name;
    

The full code sample:

var custompalette = new ThemePalette("CustomPalette");
custompalette.SetColor("Foreground", (Color)ColorConverter.ConvertFromString("#FFFF7200"));
custompalette.SetColor("Backstage.Focused", Colors.White);
var customtheme = Theme.CreateTheme(custompalette, Theme.Office2016ColorfulSE);
Theme.RegisterTheme(customtheme);
ApplicationThemeHelper.ApplicationThemeName = customtheme.Name;
See Also