Name
Name

Reputation: 529

wpf add style property to button default style

Im using the MahApps.Metro framework for my wpf window. Now the default button's of MahApps.Metro looks like this:

enter image description here

Now I want to change the style to this:

enter image description here

If I want to create this button I have to use this style property Style="{DynamicResource SquareButtonStyle}". But I dont want to write this in every Button, I want to create a default button design.


Now I added to my app.xaml file this code:

<Application.Resources>
    <ResourceDictionary>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

If I create a setter like this:

<Setter Property="Style" Value="Style="{DynamicResource SquareButtonStyle}"/>, I get 10 error's.

How can I set <Setter Property="Style" Value="Style="{DynamicResource SquareButtonStyle}"/> for every button?

Upvotes: 2

Views: 2609

Answers (1)

Xiaoy312
Xiaoy312

Reputation: 14477

You can create a new style based on another one :

<!-- 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}">

Upvotes: 3

Related Questions