7

I have written a WPF desktop app that I want to put in the Windows Store using the Desktop Bridge. The app is capable of presenting itself in light and dark modes, and using an accent color. But, to be a good citizen of Windows 10, I want to get that information from the OS, if possible.

It is my current understanding that I can get the accent color from here:

var accentBrush = SystemParameters.WindowGlassBrush;

How can I get whether Windows 10 is in its light or dark theme? Also, what method would you recommend to be notified of a change in the user's preference for either light/dark or the accent color?

Daniel Henry
  • 856
  • 7
  • 18

3 Answers3

11

There is a registry value that is updated whenever this light/dark mode setting in Windows 10 Anniversary Update or later changes. It's key is:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize

The name of the value is:

AppsUseLightTheme

If it is 1, then the theme is Light. If it is 0, then the theme is Dark. I'm going to assume Light if I can't find the key or the value (as would be the case in previous versions of Windows).

As far as I'm concerned, lindexi deserves credit for the answer. Without that comment, it didn't occur to me to investigate.

Daniel Henry
  • 856
  • 7
  • 18
4

Some simple code to give you a bool for light mode in normal WPF apps, not UWP. Never tested with high contrast modes. If the value does not exist or something goes wrong, it assumes light mode.

bool is_light_mode = true;
try
{
    var v = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", "1");
    if (v != null && v.ToString() == "0")
        is_light_mode = false;
}
catch { }
Gauthier
  • 1,251
  • 10
  • 25
4

Some users might have custom setting. Like Dark App mode and Light System mode. If user has Light System mode, it will make the Taskbar and Start menu in light color.

Screenshot for custom Light/Dark theme settings

Like @Daniel Henry said above, AppsUseLightTheme value name tells Light/Dark App mode. Similarly SystemUsesLightTheme value name tells about Light/Dark System mode. This could be helpful for apps which have System tray icons and want to make their tray icon it clearly visible.

Riz
  • 6,746
  • 16
  • 67
  • 89