How can I detect Windows 10 light/dark mode? How can I detect Windows 10 light/dark mode? windows windows

How can I detect Windows 10 light/dark mode?


You can create a Windows Runtime Component project in your solution from there you access Windows.UI.Xaml namespace. Add a method to check current ApplicationTheme like that.

public sealed class Test{    public static string CurrentTheme()    {        var isDark = Application.Current.RequestedTheme == ApplicationTheme.Dark;        if (isDark)            return "Dark";        return "Light";    }}

Add reference to windows runtime component project in your javascript app project and you can call this method where ever you want to check application theme. Take a look here for walkthrough on createing Windows Runtime Component.


I have found an easier solution, which should work in JavaScript apps as well, without requiring the Windows Runtime Component - the UISettings class:

var uiSettings = new Windows.UI.ViewManagement.UISettings();var color = uiSettings.getColorValue(                        Windows.UI.ViewManagement.UIColorType.background                       );

The color you get is either black for dark theme or white for light theme.

The class also has very useful event ColorValuesChanged which you can use to observe theme changes at runtime.


For Windows 10, the value of the AppsUseLightTheme property in the path HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize of the registry specifies wherever Windows is in dark or light mode.