How to detect Windows Application Dark mode

Deshmukh, Gaurav 30 Reputation points
2023-01-17T13:57:13.0533333+00:00

What is the way to detect windows application dark mode setting (If it is dark or light), in a C# WPF application.

Settings > Personalization > Colors > “Choose your default app mode

User's image

Screenshot from Windows 10 operating system.

I am aware of most of the ways (to detect this setting) that can be found on forums, like below. But was not able to find any official documentation for the same.

  1. Using Registry value: Path: Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize Key: AppsUseLightTheme This is most of the time reliable, but the value is only available after the user has changed the setting at least once.
  2. Using Windows UI ViewManagement This involves identifying the foreground, background color and based on that consider if it is Dark or Light theme. But this does not seem the right way (for long term).
  3. Using uxtheme.dll ‘s ShouldAppsUseDarkMode function. This did not work for me as expected (or was not able to provide the correct value most of the time).

So, require a Microsoft Windows documented, official & reliable way by means of which it is possible to detect the “Choose your default app mode” setting programmatically (WPF, C#).

Also are their similar ways to detect this in different versions of Windows (8.1, 10, 11, etc.)

Developer technologies | Windows Presentation Foundation
Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Castorix31 91,501 Reputation points
    2023-01-17T14:16:59.01+00:00

    There is this MSDN doc : Know when Dark mode is enabled about the second method

    (but I generally use the first method by reading the registry...)

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.