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.

Change theme of BaseMetroDialog

See original GitHub issue

Hello, 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.

image

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: image 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:closed
  • Created 2 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timuniecommented, Aug 25, 2021

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

  • provide different styles to the dialog (I would prefer this as it is quite flexible and also an icon can be implemented)
  • add more properties to change
  • add an enum as suggested by you @lpereira98

Happy coding Tim

1reaction
lpereira98commented, Aug 25, 2021

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:

            ResourceDictionary resourceDictionary = new ResourceDictionary();
            //Light.Red to display an error
            resourceDictionary.Add("Theme.Instance", ThemeManager.Current.GetTheme("Light.Red"));

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Hi",
                NegativeButtonText = "Go away!",
                FirstAuxiliaryButtonText = "Cancel"       
                , CustomResourceDictionary = resourceDictionary,
                ColorScheme = MetroDialogColorScheme.Accented
            };

             
            MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro! ",
                MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);

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!

Read more comments on GitHub >

github_iconTop 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 >

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