wpf-devexpress-dot-xpf-dot-bars-f2bba131.md
Populates the associated GalleryControl with available themes and allows you to choose the application’s theme.
Namespace : DevExpress.Xpf.Bars
Assembly : DevExpress.Xpf.Core.v25.2.dll
NuGet Package : DevExpress.Wpf.Core
[TargetType(typeof(Gallery))]
public class GalleryThemeSelectorBehavior :
ThemeSelectorBehavior<Gallery>
<TargetType(GetType(Gallery))>
Public Class GalleryThemeSelectorBehavior
Inherits ThemeSelectorBehavior(Of Gallery)
To use the GalleryThemeSelectorBehavior , attach it to a GalleryControl:
<Window ...
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<Grid>
<dxb:GalleryControl>
<dxb:GalleryControl.Gallery>
<dxb:Gallery ColCount="3"
IsGroupCaptionVisible="True"
IsItemCaptionVisible="True"
IsItemDescriptionVisible="True"
ItemAutoWidth="True">
<dxmvvm:Interaction.Behaviors>
<dxb:GalleryThemeSelectorBehavior />
</dxmvvm:Interaction.Behaviors>
</dxb:Gallery>
</dxb:GalleryControl.Gallery>
</dxb:GalleryControl>
</Grid>
</Window>
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();
}
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:
private void Application_Startup(object sender, ExitEventArgs e) {
ApplicationThemeHelper.UpdateApplicationThemeName();
}
Private Sub Application_Startup(ByVal sender As Object, ByVal e As StartupEventArgs)
ApplicationThemeHelper.UpdateApplicationThemeName()
End Sub
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.
You can use the Theme.ShowInThemeSelector property to hide a theme/theme category from the GalleryThemeSelectorBehavior.
The following code sample hides 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">
<Grid>
<dxb:GalleryControl>
<dxb:GalleryControl.Gallery>
<dxb:Gallery ColCount="3"
IsGroupCaptionVisible="True"
IsItemCaptionVisible="True"
IsItemDescriptionVisible="True"
ItemAutoWidth="True">
<dxmvvm:Interaction.Behaviors>
<dxb:GalleryThemeSelectorBehavior/>
</dxmvvm:Interaction.Behaviors>
</dxb:Gallery>
</dxb:GalleryControl.Gallery>
</dxb:GalleryControl>
</Grid>
</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;
}
}
}
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
Set the behavior’s inherited ShowTouchTheme property to false to hide touch themes from the GalleryThemeSelectorBehavior :
<Window ...
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<Grid>
<dxb:GalleryControl>
<dxb:GalleryControl.Gallery>
<dxb:Gallery ColCount="3"
IsGroupCaptionVisible="True"
IsItemCaptionVisible="True"
IsItemDescriptionVisible="True"
ItemAutoWidth="True">
<dxmvvm:Interaction.Behaviors>
<dxb:GalleryThemeSelectorBehavior ShowTouchThemes="False"/>
</dxmvvm:Interaction.Behaviors>
</dxb:Gallery>
</dxb:GalleryControl.Gallery>
</dxb:GalleryControl>
</Grid>
</Window>
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GalleryThemeSelectorBehavior 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-gallery-based-theme-selector/CS/GalleryThemeSelectorBehavior/MainWindow.xaml#L20
<dxmvvm:Interaction.Behaviors>
<dxb:GalleryThemeSelectorBehavior ShowTouchThemes="False" />
</dxmvvm:Interaction.Behaviors>
Object DispatcherObject DependencyObject Freezable Animatable DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase DevExpress.Mvvm.UI.Interactivity.Behavior DevExpress.Mvvm.UI.Interactivity.Behavior<Gallery> DevExpress.Xpf.Bars.ThemeSelectorBehavior<Gallery> GalleryThemeSelectorBehavior
See Also
BarSubItemThemeSelectorBehavior
BarSplitItemThemeSelectorBehavior
GalleryThemeSelectorBehavior
RibbonGalleryItemThemePaletteSelectorBehavior
HamburgerSubMenuThemeSelectorBehavior