I want to have a Button that defines no CornerRadius
and two others that do, how can I achieve this?
<Style TargetType="Button" x:Key="TabButton"> <Setter Property="Background" Value="White" /> <Setter Property="TextBlock.TextAlignment" Value="Center" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border CornerRadius="0" Background="White" BorderBrush="#ccc" BorderThickness="0,1,1,0" > <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="Button" x:Key="TabButtonFirst" BasedOn="{StaticResource TabButton}"> <Setter Property="CornerRadius" Value="3,0,0,0" /> </Style> <Style TargetType="Button" x:Key="TabButtonLast" BasedOn="{StaticResource TabButton}"> <Setter Property="CornerRadius" Value="0,0,0,3" /> </Style>
You can make rounded corners button by adding border-radius of 5px to 10px on HTML buttons.
You can achieve rounded corners on a button without having to write any XAML (other than a Style, once) and without having to replace the template or set/change any other properties. Just use an EventSetter in your style for the button's "Loaded" event and change it in code-behind.
To make the div's borders rounded, you could add the following styling: border-radius: 15px; The above sets a 15 pixel radius on the top-left, top-right, bottom-left and bottom-right corners of the element. The higher the value of the radius, the more rounded the edge becomes.
You're not limited to the dependency properties of the control you're templating. In this case, while Button
does not have a CornerRadius
property, Border
does, so you can use Border.CornerRadius
instead:
<Style TargetType="Button" x:Key="TabButton"> <Setter Property="Background" Value="White" /> <Setter Property="TextBlock.TextAlignment" Value="Center" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border CornerRadius="{TemplateBinding Border.CornerRadius}" Background="White" BorderBrush="#ccc" BorderThickness="0,1,1,0" > <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="Button" x:Key="TabButtonFirst" BasedOn="{StaticResource TabButton}"> <Setter Property="Border.CornerRadius" Value="3,0,0,0" /> </Style> <Style TargetType="Button" x:Key="TabButtonLast" BasedOn="{StaticResource TabButton}"> <Setter Property="Border.CornerRadius" Value="0,0,0,3" /> </Style>
With this approach, you no longer need to maintain multiple copies of your control template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With