Import from MahApps: Accent color when Windows determines the accent color itself
See original GitHub issuehttps://github.com/MahApps/MahApps.Metro/issues/4156
Describe the bug
Windows 10 has an option:
“Automatically select an accent color from my background”.
This will select an accent color based on the background. But the color that MahApps / ControlzEx then sets is unfortunately not the same one that Windows then uses 😕
Maybe the error is also in “ControlzEx”. But since I only used MahApps I post it here 😃
Steps to reproduce
- create a project (.net 5 for example)
- include MahApps.Metro
- Overwrite “OnStartup” in the App.xaml.cs" and add the following:
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ControlzEx.Theming.ThemeSyncMode.SyncAll;
ControlzEx.Theming.ThemeManager.Current.SyncTheme();
-
In Windows, set the “Automatically select an accent color from my background” setting.
-
Compare accent colors
Expected behavior
That the accent color MahApps.Metro uses is the same as in Windows.
Actual behavior
The accent color MahApps.Metro uses is not the same as in Windows. (Usually a little darker than the current color)
Environment
MahApps.Metro version: v2.4.7
Windows build number: Win10 21H1 [Version 119043.1151]
Visual Studio: 2019 16.10.4
Target Framework: .Net Core 5.0 (but also happens in other versions)
Screenshots
Example project
Not really useful, but here it is when needed 😃
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
WPF, Mahapps, ThemeManager, how to convert ''Accent" ...
I'd like to get System.Windows.Media.Color from MahApps.Metro.Accent . To achieve this, I tried: MahApps.Metro.ThemeManager.
Read more >Hassle-free support for Windows 10 system accent color ...
Problem is: default theme is basically blue, while in Windows 10 it would make sense to use user-chosen accent color.
Read more >XAML theme resources - Windows apps
At runtime, this resource gets the color that the user has specified as the accent color in the Windows personalization settings.
Read more >Styles
The main window or any other MetroWindow will keep the specified accent and theme in the App.
Read more >Thememanager
Thememanager. MahApps.Metro has a ThemeManager class that lets you change the theme using code-behind. It can be done in 1 line, like so:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Rerago @punker76 I was able to find out what’s wrong. As we implemented the
WindowsThemeHelper
and as we designed everything else around accent colors we were under the assumption, at least i was, that there is only one accent color. That’s not the case. Windows stores different accent colors for different things. The accent color we want/have to use is stored underHKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent\AccentPalette
which is a byte array and stores the value of interest at index0x0C
,0x0D
and0x0E
.Simplified this means: There is one accent color for the titlebar, which is also the only one we currently use, and one accent color for content inside windows. More complex: There are various accent colors, or variations of it, available for various things.
Simple solution: We switch from using the titlebar accent color to using the content accent color and everything works as currently expected.
More complex solution: We do the simple solution and in addition to that introduce the concept of different accent colors for content and the titlebar. This is what i will do in ControlzEx as that’s the basic building block for theming in MahApps.Metro and Fluent.Ribbon. We then would need to make changes to MahApps.Metro and Fluent.Ribbon to make use of the provided values. The newly provided values would at least be the titlebar color and an ideal foreground color for that. Maybe we can provide even more accent colors from ControlzEx, but that’s a thing i will have to figure out while implementing and visualizing the available colors.
Plan: Implement the simple solution as it’s a, from my point of view, non breaking change (we just use the expected value) and is easy to implement. After that i will start the more complex solution as that also requires breaking API changes, as we now need to transport more than one color. To make that possible i will most likely introduce a new type as a replacement for
Color accentColor
. I think i will introduce a new class similar toUISettings
fromWindows.UI.ViewManagement
which could then have properties likeAccent
,AccentLight1
,AccentLight2
,AccentDark1
,IdealForeground
,TitleBar
,TitleBarForeground
etc.First of all, thank you for the detailed investigation of the problem.
I think the plan sounds very good for now. With this we would have solved the accent problem for the time being. But also the more complex solution sounds very good for later use. I’m very curious what possibilities this brings with it.