3

I have a WPF application. I read (and observe) the Registry Key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme to see if (and when) Dark Mode is active or inactive. I than use WPF themes to make the application dark or light.

Anyway, I didn't found a way to change the title bar. There must be some way, because Windows Explorer also gets a dark title bar when Dark Mode is on. I didn't know of other applications that have this.

I know that CMD window also gets a black title bar in Dark mode, but I assume that is different, because Console windows are special anyway.

So, how can I tell Windows that my application supports or is in dark mode, so that the title bar becomes black?

Martini Bianco
  • 1,484
  • 1
  • 13
  • 23
  • It looks like you might be looking for something like this https://stackoverflow.com/questions/1283006/changing-wpf-title-bar-background-color – G K Dec 02 '19 at 15:41
  • That's not exactly what I wanted. The regular Windows theme must have a dark title bar, that the File explorer uses. I wondered, how to tell the System to use the dark title bar instead of the light title bar. (That means without using a Custom Chrome.) – Martini Bianco Dec 09 '19 at 10:48

3 Answers3

1

WPF have SystemColors static class with all the theme colors (more or less), use it at DynamicResource.

If you want more work (but more control) find "AccentColors P/Invoke".

If you want to change the color of the "title bar" you're looking for the "Chrome" of the window.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.windowchrome?view=netframework-4.8

DrkDeveloper
  • 939
  • 7
  • 17
  • The Windows Chrome goes into the direction. But then I'd have to realize everything myself. I assumed Windows had this already, and I already wanted to use it. – Martini Bianco Dec 09 '19 at 10:49
  • I don't know anyway to do soft and easy with WPF CLR assemblies. If you want a one click wonder you can look Mahapps.Metro: https://mahapps.com/ – DrkDeveloper Dec 09 '19 at 13:53
  • I still wonder, how to do it with system features. But this package looks very interesting. Will take a look at it. Thanks. – Martini Bianco Dec 10 '19 at 19:10
  • @MartiniBianco "how to do it with system features"... in c# wpf/uwp the answer is short: you can't. With P/Invoke or using Chrome control... You can do it almost everything. – DrkDeveloper Dec 11 '19 at 19:21
  • I think we don't understand the same thing if we talk about "system feature". If I P/Invoke something this normally is a "system feature", while using a third party library is not. - Can you tell me a way to P/Invoke to tell Windows my program should use dark Title bar? – Martini Bianco Jan 13 '20 at 14:46
0

You can't have that dark mode title bar in your WPF app. That title bar with dark mode support is for UWP apps. For your WPF app you will have to use WindowStyle="None" and create your own title bar.

This is an interesting reading related to this: https://engy.us/blog/2018/10/20/dark-theme-in-wpf/

Alexandru Dicu
  • 1,151
  • 1
  • 16
  • 24
  • 1
    Well, Windows Explorer is certainly not UWP, but still had Dark title bar. Therefore I assumed there is an API for that. But, Microsoft is probably cheating here. (Also I'm rather sure that Explorer doesn't use WindowStyle="None", or its equivalent in the Windows API.) – Martini Bianco Apr 01 '20 at 16:24
  • @MartiniBianco But windows explorer is microsoft private c++ code, they can do what ever they want behind the public APIs. With the DWM P/Invokes and a lot of work you'll can achieve something similar but, I don't recommend it, and I can't write some code to show what I mean because a) I don't know what functions have dwm and b) it is not easy or short. – DrkDeveloper May 24 '20 at 13:16
0

There is now a better way to set the window title bar color according to the theme: use the DwmSetWindowAttribute Windows API method in combination with the DWMWA_USE_IMMERSIVE_DARK_MODE constant.

It's described here:

Edgar
  • 4,348
  • 4
  • 40
  • 59