在 Mahapps Metro 对话框中覆盖按钮的样式
Overwrite button's style in a Mahapps Metro dialog
我想用自定义颜色重写 Mahapps Metro 对话框中按钮的颜色(不是使用强调色)。我最感兴趣的是更改单击时显示的按钮的颜色。这是 button 被点击时的默认样式。
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();
}
}
}
到目前为止我尝试了什么:
- 用键 'BlackBrush' 重写 Mahapps Metro 颜色(这个是
用作按钮的背景颜色)和自定义颜色;
- 重写按钮的控件模板。
有什么办法可以实现吗?
您需要处理 Metro 对话框控件的样式。你可以找到它here。要使用它,请添加
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
然后继续关注 and
我想用自定义颜色重写 Mahapps Metro 对话框中按钮的颜色(不是使用强调色)。我最感兴趣的是更改单击时显示的按钮的颜色。这是 button 被点击时的默认样式。
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();
}
}
}
到目前为止我尝试了什么:
- 用键 'BlackBrush' 重写 Mahapps Metro 颜色(这个是 用作按钮的背景颜色)和自定义颜色;
- 重写按钮的控件模板。
有什么办法可以实现吗?
您需要处理 Metro 对话框控件的样式。你可以找到它here。要使用它,请添加
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
然后继续关注