2013-07-12 175 views
4

我有以下樣式:WPF標籤樣式

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

不過,我想補充的財產CornerRadius和修改值。不幸的是,XAML錯誤說Label沒有CornerRadius屬性。我的問題,我該如何修改這個XAML?

感謝,

+0

您將需要一個依賴屬性附加到現有的控制:HTTP:/ /stackoverflow.com/questions/14318707/add-dependency-property-to-existing-net-class。我建議將此樣式應用於'TargetType =「{x:Type Border}」'並將標籤邊框包裹起來。 – Dom

回答

10

的錯誤是正確的,你不能設置在標籤的邊角半徑。

你可以做的是用一個邊框包裹標籤,並將你的風格應用到那個以獲得所需的外觀。

編輯:

的樣式資源:

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

邊框包裹標籤:

<Border Style="{StaticResource MyBorderStyle}"> 
    <Label Content="My Label" /> 
</Border> 
+0

謝謝你親切的先生。 – DoubleDunk