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,
Apply a style implicitly You can change the default appearance by setting properties, such as FontSize and FontFamily, on each TextBlock element directly. However, if you want your TextBlock elements to share some properties, you can create a Style in the Resources section of your XAML file, as shown here.
Styles provide us the flexibility to set some properties of an object and reuse these specific settings across multiple objects for a consistent look. In styles, you can set only the existing properties of an object such as Height, Width, Font size, etc. Only default behavior of a control can be specified.
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>
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