WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Feature Request: API to detect dark mode

Open whiskhub opened this issue 7 months ago • 1 comments

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
  • ShouldAppsUseDarkMode and ShouldSystemUseDarkMode in uxtheme.dll - undocumented, but work fine otherwise
  • HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize AppsUseLightTheme & 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.

whiskhub avatar Jun 19 '25 08:06 whiskhub

MS uses the methods you described (https://github.com/microsoft/microsoft-ui-xaml/blob/fb7a83b668baa612b5cc594678746dd8c1f8d8bd/src/dxaml/xcp/components/theminginterop/SystemThemingInterop.cpp#L33)

castorix avatar Jun 19 '25 18:06 castorix