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,

有帮助吗?

解决方案

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top