c# - wpf为按钮默认样式添加样式属性

标签 c# wpf

我正在使用MahApps.Metro我的 wpf 窗口的框架。现在 MahApps.Metro 的默认按钮如下所示:

enter image description here

现在我想将样式更改为:

enter image description here

如果我想创建此按钮,我必须使用此样式属性 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/

相关文章:

c# - 使用 MVVM 单击按钮时对列表框进行排序

c# - 调用相同方法的不同对象,如何设置 "caller' s"属性?

wpf - 在 xaml 中包含 xaml 元素

c# - 设置整个窗口的前景色

c# - Entity Framework 相关子查询

c# - 在 Web API 中正确使用 async/await

c# - 将 Jasig 的中央身份验证服务 (CAS) 与 ASP.NET MVC 一起使用 4/5

c# - 性能 : Returning multiple tables from Sql Server. C# .Net

c# - 非托管内存未显示在任务管理器中

c# - string.Split C# 将文本保留在定界符之外