'How to support light and dark mode title bar in wpf c#?
So, I'm trying to customize my wpf app a bit, but thought I would be better to leave the title bar as it is and not do a custom title bar. Problem is, the title bar is in light mode altough Windows is set to dark mode. Unfortunately I did not find a proper "guide" which shows how I can support light and dark mode title bars.
Most of the stackoverflow answers said that you should customize the title bar in the styles with custom buttons and everything else, but I'm not sure if this is the best approach.
Does anyone know how to switch the wpf title bar to dark mode (and of course switch it back to light mode)?
I am using WPF with .NET 5 and C# :)
I set windows to dark mode (Hell = Light, Dunkel = Dark)
EDIT 1:
I tried the answer in this post How do I get a black Title Bar for dark Mode in WPF Unfortunately I did not work like expected. First of all if I insert the style setter property for the WindowChrome I get an error that the property "WindowChrome" does not exists in the "System.Windows.Shell" namespace.
In the Setter.Value I got the same error. Maybe it is slightly different in .NET 5?
I added this code (I also tried shell:WindowChrome.WindowChrome as the docs said):
<Setter Property="shell:WindowChrome">
<Setter.Value>
<shell:WindowChrome />
</Setter.Value>
</Setter>
And those are the namespaces I tried:
xmlns:shell="System.Windows.Shell"
xmlns:shell1="http://schemas.microsoft.com/expression/blend/2008"
xmlns:shell2="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
Solution 1:[1]
There’s actually a dwmapi function that lets change the default title bar between light and dark mode in Windows 10 and 11. It’s actually pretty easy to use. Have a look here for more info: https://codingguides.quinnscomputing.com/2022/05/how-to-enable-dark-title-bar-in-windows.html.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Aiden Quinn |