5

I can create a button with rounded corners like this (from How to create/make rounded corner buttons in WPF?):

<Button>
    <Button.Resources>
        <Style TargetType="Border">
            <Setter Property="CornerRadius" Value="5"/>
        </Style>
    </Button.Resources>
</Button>

How can I define this inside a style and then apply this style for each button ? I tried creating a style like this, but the CornerRadius is not available :

<Style x:Key = "myButtonStyle" TargetType = "Button">
  <Setter Property = "Height" Value = "30"/>
  <Setter Property = "Width" Value = "80"/>
  <Setter Property = "Margin" Value = "10"/>
</Style>

Like this Pavel ?

<Style x:Key="s2" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"> 
  <Setter Property="Background" Value = "Red" />
  <Setter Property="CornerRadius" Value="5"/>
</Style>

WPF won't let me

ASh
  • 34,632
  • 9
  • 60
  • 82
Steef
  • 569
  • 5
  • 21

1 Answers1

4

You could define an implicit button style with a nested Border style:

<Style TargetType="Button">
    <Style.Resources>
        <Style TargetType="Border">
            <Setter Property="CornerRadius" Value="5"/>
        </Style>
    </Style.Resources>
    <Setter Property="Height" Value="30"/>
    <Setter Property="Width" Value="80"/>
    <Setter Property="Margin" Value="10"/>
</Style>
mm8
  • 163,881
  • 10
  • 57
  • 88