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

BarSplitItemThemeSelectorBehavior

  • 2 minutes to read

The BarSplitItemThemeSelectorBehavior populates the associated BarSplitButtonItem with available themes and allows you to choose the application’s theme.

To use the BarSplitItemThemeSelectorBehavior, attach it to a BarSplitButtonItem in a RibbonControl.

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxb:ToolBarControl>
            <dxb:BarSplitButtonItem>
                <dxmvvm:Interaction.Behaviors>
                    <dxb:BarSplitItemThemeSelectorBehavior />
                </dxmvvm:Interaction.Behaviors>
            </dxb:BarSplitButtonItem>
        </dxb:ToolBarControl>
      </StackPanel>
</Window>

BarSplitItemThemeSelectorBehavior

View Example

Persist Theme Selection between Application Runs

You can save the application’s theme to the configuration file and restore it in the next application run.

To save an applied theme, use the static ApplicationThemeHelper.SaveApplicationThemeName method to save the theme name specified in the static ApplicationThemeHelper.ApplicationThemeName property:

private void Application_Exit(object sender, StartupEventArgs e) {
    ApplicationThemeHelper.SaveApplicationThemeName();
}        

Call the static ApplicationThemeHelper.UpdateApplicationThemeName method to retrieve the theme name from the configuration file and apply it to your application:

private void Application_Startup(object sender, ExitEventArgs e) {
    ApplicationThemeHelper.UpdateApplicationThemeName();
}

Hide Themes from Theme Selector

You can use the Theme.ShowInThemeSelector property to hide a theme/theme category from the BarSplitItemThemeSelectorBehavior‘s theme gallery.

The following code sample hides the Office2007 and Metropolis theme categories, and the DeepBlue application theme:

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxb:ToolBarControl>
            <dxb:BarSplitButtonItem>
                <dxmvvm:Interaction.Behaviors>
                    <dxb:BarSplitItemThemeSelectorBehavior/>
                </dxmvvm:Interaction.Behaviors>
            </dxb:BarSplitButtonItem>
        </dxb:ToolBarControl>
    </StackPanel>
</Window>
using DevExpress.Xpf.Core;

public partial class App : Application {
    public App() {
        foreach (Theme theme in Theme.Themes.ToList()) {
            if (theme.Category == Theme.Office2007Category ||
                theme.Category == Theme.MetropolisCategory || 
                theme.Name == "DeepBlue") theme.ShowInThemeSelector = false;
        }
    }
}

Hide Touch Themes in XAML

Set the behavior’s inherited ShowTouchThemes property to false to hide touch themes from the BarSubItemThemeSelectorBehavior‘s theme gallery:

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxb:ToolBarControl>
            <dxb:BarSplitButtonItem>
                <dxmvvm:Interaction.Behaviors>
                    <dxb:BarSplitItemThemeSelectorBehavior ShowTouchThemes="False" />
                </dxmvvm:Interaction.Behaviors>
            </dxb:BarSplitButtonItem>
        </dxb:ToolBarControl>
    </StackPanel>
</Window>

Display an Applied Theme’s Icon

Set the ShowSelectedThemeGlyph property to true to display the applied theme’s icon in the BarSplitItemThemeSelectorBehavior‘s bar item:

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxb:ToolBarControl>
            <dxb:BarSplitButtonItem>
                <dxmvvm:Interaction.Behaviors>
                    <dxb:BarSplitItemThemeSelectorBehavior ShowSelectedThemeGlyph="True" />
                </dxmvvm:Interaction.Behaviors>
            </dxb:BarSplitButtonItem>
        </dxb:ToolBarControl>
    </StackPanel>
</Window>

DevExpress MVVM Behavior | BarSplitItemThemeSelectorBehavior - ShowSelectedThemeGlyph

See Also