0

I want to rewrite the color of the buttons in an Mahapps Metro dialog with a custom one (not by using Accent color). I am mostly interested in changing the color of the button that is displayed while being clicked. This is the default style of the button when is being clicked.

App.xaml:

<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/Colors.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Crimson.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml"/>
<ResourceDictionary Source="Styles.xaml" />

MainWindow.xaml:

<Grid>
    <Button
        Content="Open Metro Dialog"
        Click="Button_Click"
        Style="{StaticResource ButtonStyle}"
        />
</Grid>

MainWindow.xaml.cs

public partial class MainWindow : WindowBase
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageDialogResult dialogResult = await this.ShowMessageAsync("Close window", "Are you sure you want to close the window?", MessageDialogStyle.Affirmative);

        if (dialogResult == MessageDialogResult.Affirmative)
        {
           this.Close();
        }
    }
}

What i tried so far:

  1. Rewrite the Mahapps Metro color with key 'BlackBrush' (this one is being used as background color for the button) with a custom one;
  2. Rewrite the control template for the button.

Is there any way to achieve this?

HSBogdan
  • 200
  • 10
  • What it doesn't work? – Antoine V Sep 14 '18 at 10:16
  • I want the background color of the button to be different from the default one (the one displayed in picture) when i press the button. I am not able to overwrite the style of the Mahapps Metro dialog to achieve the desired effect. – HSBogdan Sep 14 '18 at 12:04

1 Answers1

1

you need to work on the style of the Metro dialog control. You can find it here. To use it, add

xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"

then proceed to follow this answer and this answer

Daniele Sartori
  • 1,674
  • 22
  • 38