-
-
Notifications
You must be signed in to change notification settings - Fork 11
Change Theme or Accent color (Version before 6.1.0 after 5.0.0)
Click here for versions 6.1.0 and newer
Table of Contents
This service uses the singleton pattern so only one Class is initialized by software. In order to use it you have to use
AccentColorService.Current
instead of
new AccentColorService()
This method will set your software to use the user current defined Windows accent color as the software default accent color. (Enabled by default)
AccentColorService.Current.UpdateAccentsFromWindows();
This method will set your software to use a custom Color as your Accent Color and will ignore the Windows Accent color.
AccentColorService.Current.UpdateAccents(System.Windows.Media.Color.FromRgb(255, 0, 0));
This is an event that will fire when the accent color get changed.
var currentAccentColorChanged = AccentColorService.Current.AccentColorChanged;
currentAccentColorChanged.Subscribe((accentColors)=>
{
Console.WriteLine(accentColors.SystemAccentColor.ToString());
});
Will give you the current accent colors of the application.
var currentAccentColors = AccentColorService.Current.AccentColors;
Console.WriteLine(currentAccentColors.SystemAccentColor.ToString());
Will tell you if the current accent colors are updated when changed in the windows settings.
var accentColorsUpdateFromWindows = AccentColorService.Current.AccentColorsUpdateFromWindows;
Console.WriteLine(accentColorsUpdateFromWindows.ToString());
Will tell you if the titlebar and borders are colored;
var isTitleBarAndWindowsBorderColored = AccentColorService.Current.IsTitleBarAndWindowsBorderColored;
Console.WriteLine(isTitleBarAndWindowsBorderColored.ToString());
Will tell you if it is waiting for the Windows settings to change.
var isTitleBarAndWindowsBorderColored = AccentColorService.Current.IsTitleBarAndWindowsBorderColored;
Console.WriteLine(isTitleBarAndWindowsBorderColored.ToString());
This service uses the singleton pattern so only one Class is initialized by software. In order to use it you have to use
ThemeService.Current
instead of
new ThemeService()
This method will set your software current theme. (Light or Dark)
ThemeService.Current.ChangeTheme(WindowsTheme.Light);
This method will enable Mica on the specified window it is recommended to use the extension instead.
ThemeService.Current.EnableBackdrop(this, BackdropType.Mica, 20);
This is an event that will fire when the theme get changed.
var currentThemeChanged = ThemeService.Current.ThemeChanged;
currentThemeChanged.Subscribe((windowsTheme)=>
{
Console.WriteLine(windowsTheme.ToString());
});
Will give you a list of all the current windows with backdrops enabled.
var backdropEnabledWindows = ThemeService.Current.BackdropEnabledWindows;
foreach(var window in backdropEnabledWindows)
{
Console.WriteLine(window.Name);
}
Will give you the current theme of the application.
var currentTheme = ThemeService.Current.CurrentTheme;
Console.WriteLine(currentTheme.ToString());
Will tell if the service is listening for theme change.
var currentThemeAwareness = ThemeService.Current.IsThemeAware;
Console.WriteLine(currentThemeAwareness); //True by default
Determines whether the title bar and borders are accented.
var areTitleBarAndBordersAccented = WindowsAccentHelper.AreTitleBarAndBordersAccented();
Console.WriteLine(areTitleBarAndBordersAccented.ToString());
Console output: False (As I don't have it activated on my machine)
Gets the accent color for the system.
var currentAccentColors = WindowsAccentHelper.GetAccentColor();
Console.WriteLine(currentAccentColors.SystemAccentColor);
Console output: #FF0078D4 (As it is the current color I am using)
This method allows you to get the current Windows theme.
var currentTheme = WindowsThemeHelper.GetCurrentWindowsTheme();
Console.WriteLine(currentTheme.ToString());
Console output: Dark (As I am using Dark Theme on Windows)
This method allows you to get the Ressource Uri for the specified theme.
var themeRessource = WindowsThemeHelper.WindowsThemeToResourceTheme(WindowsTheme.Dark);
Console.WriteLine(themeRessource.ToString());
Console output: pack://application:,,,/MicaWPF;component/Styles/Themes/MicaDark.xaml
Both services are accessible via DependencyInjection see dependency injection implementation.
The documentation is maintained by @Simnico99. This Library is distributed under an MIT License.