我正在使用MahApps.Metro我的 wpf 窗口的框架。现在 MahApps.Metro 的默认按钮如下所示:
现在我想将样式更改为:
如果我想创建此按钮,我必须使用此样式属性 Style="{DynamicResource SquareButtonStyle}"
。但我不想在每个按钮中都写这个,我想创建一个默认的按钮设计。
现在我添加到我的 app.xaml
将此代码归档:
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Button">
<Setter Property="Margin" Value="5"/>
</Style>
</ResourceDictionary>
</Application.Resources>
如果我创建这样的 setter :
<Setter Property="Style" Value="Style="{DynamicResource SquareButtonStyle}"/>
,我收到 10 个错误。
如何设置<Setter Property="Style" Value="Style="{DynamicResource SquareButtonStyle}"/>
每个按钮?
最佳答案
您可以基于另一种样式创建新样式:
<!-- based on the current generic style -->
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<!-- based on a specific style -->
<Style TargetType="Button" BasedOn="{DynamicResource SquareButtonStyle}">
关于c# - wpf为按钮默认样式添加样式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32188980/