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?
Select Start > Settings . Select Personalization > Colors. In the list for Choose your mode, select Custom. In the list for Choose your default Windows mode, select Dark.
If you'd like to keep Dark Mode enabled for your OS, but want to turn it off for individual Office apps, go to the app preferences (For example: Word > Preferences) and on the General tab look for the Personalize group. There you'll find Turn off Dark Mode.
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.
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 { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With