WPF label styling

33,522

The error is correct, you cannot set a corner radius on a Label.

What you can do is wrap the Label with a Border and apply your style to that to get the desired look.

EDIT:

The Style Resource:

<Style x:Key="MyBorderStyle" TargetType="Border">
      <Setter Property="BorderBrush" Value="White" />
      <Setter Property="BorderThickness" Value="2" />
      <Setter Property="CornerRadius" Value="3" />
</Style>

The border wrapped label:

<Border Style="{StaticResource MyBorderStyle}">
    <Label Content="My Label" />
</Border>
Share:
33,522
DoubleDunk
Author by

DoubleDunk

Updated on July 20, 2020

Comments

  • DoubleDunk
    DoubleDunk almost 4 years

    I have the following style:

    <Style x:Key="WhiteStyle" TargetType="{x:Type Label}">               
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="BorderThickness" Value="2"/>    
    </Style>
    

    However, I would like to add the property CornerRadius and modify the value. Unfortunately, the XAML error says a Label does not have a CornerRadius property. My question, How must I modify this XAML?

    Thanks,