You can simplify the operation of saving, retrieving and selecting the Application theme and backdrop. All operations are performed automatically.
Backdrops
Name
None
Mica
MicaAlt
Acrylic
AcrylicThin
Transparent
Events
Name
ThemeChanged
BackdropChanged
Properties
Name
IsDark
ElementTheme
ActualTheme
BackdropType
Methods
Name
Window
SetElementThemeAsync
SetElementThemeWithoutSaveAsync
SetBackdropTypeAsync
SetBackdropTypeWithoutSaveAsync
GetAcrylicSystemBackdrop
GetMicaSystemBackdrop
GetSystemBackdrop
OnThemeComboBoxSelectionChanged
SetThemeComboBoxDefaultItem
OnBackdropComboBoxSelectionChanged
SetBackdropComboBoxDefaultItem
OnThemeRadioButtonChecked
SetThemeRadioButtonDefaultItem
OnBackdropRadioButtonChecked
SetBackdropRadioButtonDefaultItem
Dispose
ConfigureAutoSave
ConfigureElementTheme
ConfigureBackdrop
Initialize
Simple Usage
1 2
var themeService = new ThemeService(); themeService.Initialize(window);
Configs
there are some configure methods:
ConfigureBackdrop
If you use the ConfigureBackdrop, the themeService will automatically save and restore the SystemBackdrop (if ConfigureAutoSave is enabled (by default it is enabled))
If you use the ConfigureElementTheme, the themeService will automatically save and restore the ElementTheme (if ConfigureAutoSave is enabled (by default it is enabled))
var themeService = GetService<IThemeService>() as ThemeService; themeService.Initialize(Window);
Multi-Window
if you have multiple window, you need to use WindowHelper.TrackWindow method, before Activate your window.
1 2 3
Window myWindow = new Window(); WindowHelper.TrackWindow(myWindow); myWindow.Activate();
TintColor (Mica and Acrylic)
There are no built-in methods for working with TintColor. However, you can access the current backdrop by calling GetAcrylicSystemBackdrop or GetMicaSystemBackdrop, and then modify the TintColor property manually.
Auto Change Theme/Backdrop and Auto Load Default Item
if you want to set defualt item for combobox or radiobuttons, and auto switch between themes or backdrops just add following line in your xaml
Auto Change Theme/Backdrop and Auto Load Default Item (Old Methods)
ComboBox
if you want to handle everything by yourself, first of all remove dev:ThemeServiceAttach.ThemeService="{x:Bind local:App.Current.GetThemeService}" and then add your events:
for changing and saving application theme / backdrop:
for selecting currect combobox item when page is loading, you can call SetThemeComboBoxDefaultItem or SetBackdropComboBoxDefaultItem method in Page Loaded event:
if you want to handle everything by yourself, first of all remove dev:ThemeServiceAttach.ThemeService="{x:Bind local:App.Current.GetThemeService}" and then add your events:
for changing and saving application theme / backdrop:
for selecting currect radiobutton item when page is loading, you can call SetThemeRadioButtonDefaultItem or SetBackdropRadioButtonDefaultItem method in Page Loaded event: