Flyout color when change color in a single MetroWindow
See original GitHub issueDescribe 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)
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.
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.
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:
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:
- Created 2 years ago
- Comments:8 (1 by maintainers)
The culprit for all of this is that inside of
ThemeManagerOnIsThemeChanged
inMetroWindow
the new theme is applied to all Flyouts contained in that window. But theThemeChanged
event fromThemeManager
is fired globally and not on a per Window basis. Instead of usinge.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 frome.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.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