Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import from MahApps: Accent color when Windows determines the accent color itself

See original GitHub issue

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;
  • 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)


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)



Example project

Not really useful, but here it is when needed 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

batzencommented, Aug 25, 2021

@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 under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent\AccentPalette which is a byte array and stores the value of interest at index 0x0C, 0x0D and 0x0E.

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 to UISettings from Windows.UI.ViewManagement which could then have properties like Accent, AccentLight1, AccentLight2, AccentDark1, IdealForeground, TitleBar, TitleBarForeground etc.

Reragocommented, Aug 25, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >
The main window or any other MetroWindow will keep the specified accent and theme in the App.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found