Change theme of BaseMetroDialog
See original GitHub issueHello, im very new to this framework and im trying to change the theme of a BaseMetroDialog.
My goal is simple, if i have an error message i want the theme to be Red, if i have a warning message i want the theme to be Orange and so on… I tried to do something like this: https://stackoverflow.com/questions/44881218/metrodialog-with-custom-background-color but i got nothing.
Now im trying to execute this code:
var themes = ThemeManager.Current.DetectTheme().Resources;
themes["Theme.ThemeInstance"] = ThemeManager.Current.GetTheme("Light.Red");
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "Hi",
NegativeButtonText = "Go away!",
FirstAuxiliaryButtonText = "Cancel",
CustomResourceDictionary = themes,
ColorScheme = MetroDialogColorScheme.Theme
};
MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro! ",
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);
But it was also unsuccessful.
But i noticed something interesting, if i change to this:
var themes = ThemeManager.Current.DetectTheme().Resources;
themes["Theme.ThemeInstance"] = Brushes.Red;
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "Hi",
NegativeButtonText = "Go away!",
FirstAuxiliaryButtonText = "Cancel",
CustomResourceDictionary = themes,
ColorScheme = MetroDialogColorScheme.Inverted
};
MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro! ",
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);
i get an exception:
which means that, this value is converted somewhere to ControlzEx.Theming.Theme, but still it’s never used or displayed.
I’d be very pleased for some help on this!
Environment
MahApps.Metro version: v2.4.7
Windows build number: Win10
Visual Studio: 2019 16.10.2
Target Framework: .Net Core 3.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
How to change MahApps.Metro dialog content template ...
I've found in BaseMetroDialog.xaml that the message dialog is divided into three parts vertically: 25% space on left side, 50% for the content ......
Read more >BaseMetroDialog.cs
Metro/Controls/Dialogs/BaseMetroDialog.cs ... the metro dialog should use the default black/white appearance (theme) or try to use the current accent.
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 >BaseMetroDialog, MahApps.Metro.Controls.Dialogs ...
Dialogs BaseMetroDialog - 45 examples found. ... Theme DetectTheme(BaseMetroDialog dialog) { if (dialog == null) ... Shutdown(); } else { switch (obj.
Read more >FormDesigner/MahApps.Metro.xml 4.8.2
Handles changes to the 'Password' attached property. ... BaseMetroDialog.Title"> ... Dark"> <summary> The dark theme. This is the default theme. </summary>
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
Hi all
I saw the same, any custom Style or Brush is ignored. So I think this is a bug and should be fixed in a separate ticket.
The other question is a change request. I think Jan @punker76 should give us a feedback how one should handle that the easiest
Ideas could be
Happy coding Tim
I feel like MetroDialogSettings.CustomResourceDictionary is a bit ignored, it just doesn’t change anything on BaseDialog.
I’ve made a change in this library to do what i want: Commit
Usage:
With this, the whole Dialog theme will be changed to the theme specified on MetroDialogSettings.CustomResourceDictionary with key=“Theme.Instance”. Even tho this solves my problem, i would still prefer to have one more parameter on ShowMessageAsync describing the type of message (Error, warning, info,… ). Another question is, could my solution be part of this repository ? Should i make a PR ?
@timunie thanks for trying to help!