How to detect Windows Application Dark mode

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

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.)

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
125 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,170 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
1,888 questions
C#
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.
6,920 questions
{count} votes

Accepted answer
  1. answered 2023-01-17T14:16:59.01+00:00
    Castorix31 65,331 Reputation points

    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...)


0 additional answers

Sort by: Most helpful