Skip to content

Change Theme or Accent color (Version before 6.1.0 after 5.0.0)

Simnico99 edited this page Jul 14, 2023 · 1 revision

Click here for versions 6.1.0 and newer

Contents

Table of Contents
  1. AccentColorService
  2. ThemeService
  3. WindowsAccentHelper
  4. WindowsThemeHelper
  5. Depedency Injection

AccentColorService

Usage

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()

Methods

UpdateAccentsFromWindows()

This method will set your software to use the user current defined Windows accent color as the software default accent color. (Enabled by default)

Usage Exemple:
AccentColorService.Current.UpdateAccentsFromWindows();
Results:

image image

UpdateAccents(Color)

This method will set your software to use a custom Color as your Accent Color and will ignore the Windows Accent color.

Usage Exemple:
AccentColorService.Current.UpdateAccents(System.Windows.Media.Color.FromRgb(255, 0, 0));
Results:

image image

Properties

AccentColorChanged { get; }

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());
});

AccentColors { get; }

Will give you the current accent colors of the application.

Usage Exemple:
var currentAccentColors = AccentColorService.Current.AccentColors;
Console.WriteLine(currentAccentColors.SystemAccentColor.ToString());

AccentColorsUpdateFromWindows { get; }

Will tell you if the current accent colors are updated when changed in the windows settings.

Usage Exemple:
var accentColorsUpdateFromWindows = AccentColorService.Current.AccentColorsUpdateFromWindows;
Console.WriteLine(accentColorsUpdateFromWindows.ToString());

IsTitleBarAndWindowsBorderColored { get; }

Will tell you if the titlebar and borders are colored;

Usage Exemple:
var isTitleBarAndWindowsBorderColored = AccentColorService.Current.IsTitleBarAndWindowsBorderColored;
Console.WriteLine(isTitleBarAndWindowsBorderColored.ToString());

IsTitleBarAndBorderAccentAware { get; }

Will tell you if it is waiting for the Windows settings to change.

Usage Exemple:
var isTitleBarAndWindowsBorderColored = AccentColorService.Current.IsTitleBarAndWindowsBorderColored;
Console.WriteLine(isTitleBarAndWindowsBorderColored.ToString());

ThemeService

Usage

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()

Methods

ChangeTheme(WindowsTheme)

This method will set your software current theme. (Light or Dark)

Usage Exemple:
ThemeService.Current.ChangeTheme(WindowsTheme.Light);
Results:

image

EnableBackdrop(Window, BackdropType, int(CaptionHeight))

This method will enable Mica on the specified window it is recommended to use the extension instead.

Usage Exemple:
ThemeService.Current.EnableBackdrop(this, BackdropType.Mica, 20);
Results:

image

Properties

ThemeChanged { get; }

This is an event that will fire when the theme get changed.

var currentThemeChanged = ThemeService.Current.ThemeChanged;
currentThemeChanged.Subscribe((windowsTheme)=> 
{
	Console.WriteLine(windowsTheme.ToString());
});

BackdropEnabledWindows { get; }

Will give you a list of all the current windows with backdrops enabled.

Usage Exemple:
var backdropEnabledWindows = ThemeService.Current.BackdropEnabledWindows;
foreach(var window in backdropEnabledWindows)
{
	Console.WriteLine(window.Name);
}

CurrentTheme { get; }

Will give you the current theme of the application.

Usage Exemple:
var currentTheme = ThemeService.Current.CurrentTheme;
Console.WriteLine(currentTheme.ToString());

IsThemeAware { get; }

Will tell if the service is listening for theme change.

Usage Exemple:
var currentThemeAwareness = ThemeService.Current.IsThemeAware;
Console.WriteLine(currentThemeAwareness); //True by default

WindowsAccentHelper

Methods

AreTitleBarAndBordersAccented()

Determines whether the title bar and borders are accented.

Usage Exemple:
var areTitleBarAndBordersAccented = WindowsAccentHelper.AreTitleBarAndBordersAccented();
Console.WriteLine(areTitleBarAndBordersAccented.ToString());
Results:

Console output: False (As I don't have it activated on my machine)

GetAccentColor()

Gets the accent color for the system.

Usage Exemple:
var currentAccentColors = WindowsAccentHelper.GetAccentColor();
Console.WriteLine(currentAccentColors.SystemAccentColor);
Results:

Console output: #FF0078D4 (As it is the current color I am using)

WindowsThemeHelper

Methods

GetCurrentWindowsTheme()

This method allows you to get the current Windows theme.

Usage Exemple:
var currentTheme = WindowsThemeHelper.GetCurrentWindowsTheme();
Console.WriteLine(currentTheme.ToString());
Results:

Console output: Dark (As I am using Dark Theme on Windows)

WindowsThemeToResourceTheme(WindowsTheme)

This method allows you to get the Ressource Uri for the specified theme.

Usage Exemple:
var themeRessource = WindowsThemeHelper.WindowsThemeToResourceTheme(WindowsTheme.Dark);
Console.WriteLine(themeRessource.ToString());
Results:

Console output: pack://application:,,,/MicaWPF;component/Styles/Themes/MicaDark.xaml

Dependency Injection

Both services are accessible via DependencyInjection see dependency injection implementation.

Clone this wiki locally