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”
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.
- Using Registry value:
This is most of the time reliable, but the value is only available after the user has changed the setting at least once.
- 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).
- 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.)