Back to Devexpress

RibbonGalleryItemThemeSelectorBehavior Class

wpf-devexpress-dot-xpf-dot-ribbon-68d643fb.md

latest11.2 KB
Original Source

RibbonGalleryItemThemeSelectorBehavior Class

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

Namespace : DevExpress.Xpf.Ribbon

Assembly : DevExpress.Xpf.Ribbon.v25.2.dll

NuGet Package : DevExpress.Wpf.Ribbon

Declaration

csharp
[TargetType(typeof(RibbonGalleryBarItem))]
public class RibbonGalleryItemThemeSelectorBehavior :
    GalleryBarItemThemeSelectorBehavior<RibbonGalleryBarItem>
vb
<TargetType(GetType(RibbonGalleryBarItem))>
Public Class RibbonGalleryItemThemeSelectorBehavior
    Inherits GalleryBarItemThemeSelectorBehavior(Of RibbonGalleryBarItem)

Remarks

To use the RibbonGalleryItemThemeSelectorBehavior , attach it to a RibbonGalleryBarItem in a RibbonControl.

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

View Example

Persist Theme Selection between Application Runs

You 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:

csharp
private void Application_Exit(object sender, StartupEventArgs e) {
    ApplicationThemeHelper.SaveApplicationThemeName();
}
vb
Private Sub Application_Exit(ByVal sender As Object, ByVal e As StartupEventArgs)
    ApplicationThemeHelper.SaveApplicationThemeName()
End Sub

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

csharp
private void Application_Startup(object sender, ExitEventArgs e) {
    ApplicationThemeHelper.UpdateApplicationThemeName();
}
vb
Private Sub Application_Startup(ByVal sender As Object, ByVal e As StartupEventArgs)
    ApplicationThemeHelper.UpdateApplicationThemeName()
End Sub

Display Windows System Color Theme

You can set the inherited ShowWin10SystemColorTheme property to true to display the Windows 10 System Colors theme in the theme selector. This theme takes the Windows app mode and accent color settings, applies it to your application, and updates your app appearance when a user changes these OS settings.

Refer to the following topic for more information: Use Windows Accent Color and App Mode.

Hide Themes from Theme Selector

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

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

xaml
<Window ...
      xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <Grid>
        <dxr:RibbonControl>
            <dxr:RibbonDefaultPageCategory>
                <dxr:RibbonPage Caption="Theme">
                    <dxr:RibbonPageGroup Caption="Application Theme">
                        <dxr:RibbonGalleryBarItem>
                            <dxmvvm:Interaction.Behaviors>
                                <dxr:RibbonGalleryItemThemeSelectorBehavior />
                            </dxmvvm:Interaction.Behaviors>
                        </dxr:RibbonGalleryBarItem>
                    </dxr:RibbonPageGroup>
                </dxr:RibbonPage>
            </dxr:RibbonDefaultPageCategory>
        </dxr:RibbonControl>
      </Grid>
</Window>
csharp
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;
        }
    }
}
vb
Imports DevExpress.Xpf.Core

Public Partial Class App
    Inherits Application

    Public Sub New()
        For Each theme As Theme In Theme.Themes.ToList()
            If theme.Category = Theme.Office2007Category OrElse theme.Category = Theme.MetropolisCategory OrElse theme.Name = "DeepBlue" Then theme.ShowInThemeSelector = False
        Next
    End Sub
End Class

Hide Touch Themes in XAML

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

xaml
<Window ...
      xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <Grid>
        <dxr:RibbonControl>
            <dxr:RibbonDefaultPageCategory>
                <dxr:RibbonPage Caption="Theme">
                    <dxr:RibbonPageGroup Caption="Application Theme">
                        <dxr:RibbonGalleryBarItem>
                            <dxmvvm:Interaction.Behaviors>
                                <dxr:RibbonGalleryItemThemeSelectorBehavior ShowTouchThemes="False"/>
                            </dxmvvm:Interaction.Behaviors>
                        </dxr:RibbonGalleryBarItem>
                    </dxr:RibbonPageGroup>
                </dxr:RibbonPage>
            </dxr:RibbonDefaultPageCategory>
        </dxr:RibbonControl>
      </Grid>
</Window>

The following code snippets (auto-collected from DevExpress Examples) contain references to the RibbonGalleryItemThemeSelectorBehavior class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-mvvm-behaviors-barItems-based-theme-selectors/CS/WpfApplication1/MainWindow.xaml#L63

xml
<dxmvvm:Interaction.Behaviors>
    <dxr:RibbonGalleryItemThemeSelectorBehavior />
</dxmvvm:Interaction.Behaviors>

wpf-mvvm-behaviors-gallery-based-theme-palette-selector/CS/MainWindow.xaml#L18

xml
<dxmvvm:Interaction.Behaviors>
    <dxr:RibbonGalleryItemThemeSelectorBehavior ShowTouchThemes="False"/>
</dxmvvm:Interaction.Behaviors>

wpf-scheduler-disable-resource-colorization/CS/DXSample/MainWindow.xaml#L26

xml
<dxmvvm:Interaction.Behaviors>
    <dxr:RibbonGalleryItemThemeSelectorBehavior />
</dxmvvm:Interaction.Behaviors>

Inheritance

Show 13 items

Object DispatcherObject DependencyObject Freezable Animatable DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase DevExpress.Mvvm.UI.Interactivity.Behavior DevExpress.Mvvm.UI.Interactivity.Behavior<RibbonGalleryBarItem> DevExpress.Xpf.Bars.ThemeSelectorBehavior<RibbonGalleryBarItem> DevExpress.Xpf.Bars.BarItemThemeSelectorBehavior<RibbonGalleryBarItem> DevExpress.Xpf.Bars.GalleryBarItemThemeSelectorBehavior<RibbonGalleryBarItem> RibbonGalleryItemThemeSelectorBehavior RibbonGalleryItemThemePaletteSelectorBehavior

See Also

Behaviors

BarSubItemThemeSelectorBehavior

BarSplitItemThemeSelectorBehavior

GalleryThemeSelectorBehavior

RibbonGalleryItemThemePaletteSelectorBehavior

HamburgerSubMenuThemeSelectorBehavior

RibbonGalleryItemThemeSelectorBehavior Members

DevExpress.Xpf.Ribbon Namespace