[英]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). 我想用自定义对话框重写Mahapps Metro对话框中按钮的颜色(而不是使用强调颜色)。 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: 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: MainWindow.xaml:
<Grid>
<Button
Content="Open Metro Dialog"
Click="Button_Click"
Style="{StaticResource ButtonStyle}"
/>
</Grid>
MainWindow.xaml.cs 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: 到目前为止我尝试过的是:
Is there any way to achieve this? 有什么办法可以做到这一点?
you need to work on the style of the Metro dialog control. 您需要使用Metro对话框控件的样式。 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 然后继续按照这个答案和这个答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.