简体   繁体   中英

Overwrite button's style in a Mahapps Metro dialog

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM