In previous versions of Windows, you would use the SystemColors
class to get the corresponding colors. However, it does not map to the Windows 10 light and dark mode colors, as you can see in this issue. It will only be useful in in high contrast mode to a certain extent. The SystemParameters.WindowGlassBrush
will only give you the accent color, which is not the window chrome color in general, but only if you explicitly apply it to window frames and titles in the system settings.
I have not found any way to either get the window chrome color or the title bar color directly, anywhere.
What you can do instead, is detect if Light Mode or Dark Mode is enabled for apps and change the color in your application depending on it, but you have to define the colors yourself. The following snippet uses the registry to find out which mode is enabled. If the registry key is not defined, it will return null
.
var value = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", null);
var isAppLightTheme = value != null ? Convert.ToBoolean(value) : (bool?)null;
If you also want to cover the case when the access color is set as window frame or title bar color, use the registry entry below. The problem in this scenario is that Windows will set the title text color to either black or white, depending on the accent color for better readability. As above, you have to handle this manually.
var value = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorPrevalence", null);
var isTitleFrameAccentColored = value != null ? Convert.ToBoolean(value) : (bool?)null;
In order to access the registry, you need the Microsoft.Win32
namespace. If you use .NET Core you can install the Microsoft.Win32.Registry
package to access the Registry
class.