question-mark
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.

Flyout color when change color in a single MetroWindow

See original GitHub issue

Describe the bug

Hello everyone! I have a problem with changing the color to a single window. I will try to explain it with an example.

Expected behavior

I was hoping to change the color of the secondary window without affecting the main one

Actual behavior

In my Application.xaml, in ResourcesDictionary, I have this:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
    <ResourceDictionary Source="/Resources/Icons.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TabControl.xaml" />
</ResourceDictionary.MergedDictionaries>

The user can choose which color he wants to apply. In the example, the user has chosen Pink. Starting the application, I apply the theme and color that the user has saved in the configuration, using this:

ThemeManager.Current.ChangeTheme(Application.Current, My.Settings.EstiloHUM, My.Settings.ColorHUM)

image

When I open the secondary window, according to a series of characteristics, that window may want to open it in Steel color. I use this:

ThemeManager.Current.ChangeTheme(Me, "Light.Steel")

So far so good.

image

But if I look in the main window, everything is still Pink except for this flyout (which has Theme = “Accent” in the .xaml). This and other flyouts from main window are in design code (.xaml) and I used them as filters for different sections.

image

And also, when I close the second window, the main one seems to go back to Pink, but that flyout continues to show with Steel, and others flyouts, which has Theme = “Adapt”, the content shows like this:

image

When closing the secondary window I have tried to correct it using:

ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAccent
ThemeManager.Current.SyncTheme()

But it puts everything back to Blue, so I reassign the color Pink: ThemeManager.Current.ChangeTheme (Application.Current, My.Settings.EstiloHUM, My.Settings.ColorHUM)

This solves it, but it entails a small delay of 3-4 seconds.

Has anyone else had this problem with the flyouts contained in the main window when changing the color in a secondary window? Thanks for your help!

Environment

.Net Framework 4.6.2
ControlzEx version: 4.4.0
MahApps.Metro version: 2.4.5
Visual Studio 2015 version 14.0 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
batzencommented, May 4, 2021

The culprit for all of this is that inside of ThemeManagerOnIsThemeChanged in MetroWindow the new theme is applied to all Flyouts contained in that window. But the ThemeChanged event from ThemeManager is fired globally and not on a per Window basis. Instead of using e.NewTheme for changing flyout themes, unconditionally, the theme should be detected from the current window instance and that theme should then be used if the event sender is null, if the event sender is the current window take the theme from e.NewTheme. At least that’s what i think would be the right solution.

We should also investigate the delays @recetarioMDWiki mentioned. My rough guess is that the application contains a lot of flyouts and because ThemeChanged is fired globally every flyout changes it’s theme. So fixing the flyout theme change code should, in theory, also fix the delays.

1reaction
timuniecommented, May 4, 2021

Ok I can confirm that there is an issue where all flyout changes theme whereas the window doesnt. I managed to reproduce this in the demo as well:

https://github.com/timunie/MahApps.Metro/tree/FlyoutThemingIssueInDemo

/cc @punker76 @batzen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flyout not changing accent colors/themes... · Issue #1646
The flyout control does not seem to be changing accent colors or themes if it is changed once the program is running. Any...
Read more >
Flyout color when change color in a single MetroWindow
Hello everyone! I have a problem with changing the color to a single window. I will try to explain it with an example....
Read more >
Flyouts
The Flyout theme will match the host window's accent color. This option needs more action by the user, such as using the correct...
Read more >
Mahapps.Flyouts - Content Binding
I'm trying to dynamically bind a Flyout content to a view, like I would do to a TabControl, but when I load the...
Read more >
Change colour of icon and text if selected in FlyoutItem
Change colour of icon and text if selected in FlyoutItem · Apply background colour to Flyout (currently it is still default black in...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found