2

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?

1 Answer 1

3

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}">
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer! :) I used this code: <Style TargetType="Button" BasedOn="{StaticResource SquareButtonStyle}">, with StaticResource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.