Feature Request: API to detect dark mode
To this date, there is no proper API to detect whether dark mode is enabled in Windows.
The proposed API must provide:
- Selected app mode theme
- Notifications when the selected app mode theme changes
- Selected system mode theme
- Notifications when the selected system mode theme changes
It is important to also detect system mode themes, for example to be able to change the NotifyIcon icon color depending on the Windows taskbar theme.
The proposed API should also provide:
- Whether high contrast mode is enabled
- Which high contrast mode is set
- Notifications when high contrast mode changes (these are already provided with WinRT AccessibilitySettings, but could be added to a new Windows App SDK API as well).
Currently, there are only multiple workarounds, which are either undocumented or flawed:
- UISettings.GetColorValue() with a formula to detect if the color is light - documented, but hacky formula and does not provide system mode theme
-
ShouldAppsUseDarkModeandShouldSystemUseDarkModeinuxtheme.dll- undocumented, but work fine otherwise -
HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\PersonalizeAppsUseLightTheme&SystemUsesLightTheme- undocumented, but work fine otherwise
There was already an issue on GitHub, #5476 "Dark mode for applications", but it was closed even though the issue is not yet resolved. I am opening this issue to avoid the issue getting lost.
MS uses the methods you described (https://github.com/microsoft/microsoft-ui-xaml/blob/fb7a83b668baa612b5cc594678746dd8c1f8d8bd/src/dxaml/xcp/components/theminginterop/SystemThemingInterop.cpp#L33)