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

BarSubItemThemeSelectorBehavior Class

Populates the associated BarSubItem with available themes and allows you to choose the application’s theme.

Namespace: DevExpress.Xpf.Bars

Assembly: DevExpress.Xpf.Core.v20.2.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Core, DevExpress.Wpf.Core

Declaration

[TargetType(typeof(BarSubItem))]
public class BarSubItemThemeSelectorBehavior :
    BarItemThemeSelectorBehavior<BarSubItem>

Remarks

To use the BarSubItemThemeSelectorBehavior, attach it to a BarSubItem in a RibbonControl.

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxr:RibbonControl>
            <dxr:RibbonDefaultPageCategory>
                <dxr:RibbonPage Caption="Theme">
                    <dxr:RibbonPageGroup Caption="Application Theme">
                        <dxb:BarSubItem>
                            <dxmvvm:Interaction.Behaviors>
                                <dxb:BarSubItemThemeSelectorBehavior />
                            </dxmvvm:Interaction.Behaviors>
                        </dxb:BarSubItem>
                    </dxr:RibbonPageGroup>
                </dxr:RibbonPage>
            </dxr:RibbonDefaultPageCategory>
        </dxr:RibbonControl>
    </StackPanel>
</Window>

BarSubItemThemeSelectorBehavior

View Example

Display Modes

You can use the BarSubItemThemeSelectorBehavior.ShowMode property to choose any of the following display modes:

List

Themes are displayed in a list.

BarSubItemThemeSelectorBehavior_List

GroupedList

Themes are displayed in a list and grouped by category.

BarSubItemThemeSelectorBehavior_GroupedList

GroupedInSubMenus

Themes are grouped by category and displayed in sub menus.

BarSubItemThemeSelectorBehavior_GroupedInSubMenus

Persist Theme Selection between Application Runs

Use can save the application’s theme to the configuration file and restore it on 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 BarSubItemThemeSelectorBehavior.

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:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxr:RibbonControl>
            <dxr:RibbonDefaultPageCategory>
                <dxr:RibbonPage Caption="Theme">
                    <dxr:RibbonPageGroup Caption="Application Theme">
                        <dxb:BarSubItem>
                            <dxmvvm:Interaction.Behaviors>
                                <dxb:BarSubItemThemeSelectorBehavior/>
                            </dxmvvm:Interaction.Behaviors>
                        </dxb:BarSubItem>
                    </dxr:RibbonPageGroup>
                </dxr:RibbonPage>
            </dxr:RibbonDefaultPageCategory>
        </dxr:RibbonControl>
    </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:

<Window ...
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
    xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <StackPanel>
        <dxr:RibbonControl>
            <dxr:RibbonDefaultPageCategory>
                <dxr:RibbonPage Caption="Theme">
                    <dxr:RibbonPageGroup Caption="Application Theme">
                        <dxb:BarSubItem>
                            <dxmvvm:Interaction.Behaviors>
                                <dxb:BarSubItemThemeSelectorBehavior ShowTouchThemes="False" />
                            </dxmvvm:Interaction.Behaviors>
                        </dxb:BarSubItem>
                    </dxr:RibbonPageGroup>
                </dxr:RibbonPage>
            </dxr:RibbonDefaultPageCategory>
        </dxr:RibbonControl>
    </StackPanel>
</Window>

Inheritance

Show 11 items
Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<BarSubItem>
DevExpress.Xpf.Bars.ThemeSelectorBehavior<BarSubItem>
DevExpress.Xpf.Bars.BarItemThemeSelectorBehavior<BarSubItem>
BarSubItemThemeSelectorBehavior
See Also