2010-06-28 10 views
7

Mam etykietę w WPF, którą chcę zmienić, aby miała zaokrąglone rogi.Projekt etykiety WPF

Mam poniższy kod już:

<Style TargetType="{x:Type Label}">   
    <Setter Property="Background" Value="Red"/> 
    <Setter Property="Margin" Value="2,2,2,2"/> 
    <Setter Property="BorderThickness" Value="2"/> 
    <Setter Property="BorderBrush" Value="Blue"/> 
    </Style> 

Czy ktoś może pomóc proszę o jak Dodam promieniu rożny dla tej wytwórni

wiele dzięki

Odpowiedz

15

Musisz zmienić ControlTemplate dla etykiety, aby uzyskać zaokrąglone rogi. Sam formant Label nie ujawnia właściwości CornerRadius.

Dodaj do swojego stylu następujące elementy, aby uzyskać zaokrąglone krawędzie etykiety. Ustawiam ją dowolnie na "3" poniżej, ale możesz ją ustawić zgodnie ze swoimi potrzebami.

<Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type Label}"> 
      <Border BorderBrush="{TemplateBinding BorderBrush}" 
       BorderThickness="{TemplateBinding BorderThickness}" 
       Background="{TemplateBinding Background}" 
       Padding="{TemplateBinding Padding}" 
       SnapsToDevicePixels="true" 
       CornerRadius="3"> 
       <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
      </Border> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsEnabled" Value="false"> 
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Setter.Value> 
</Setter> 
+0

Doskonale - dziękuję – Bruie

3

Używanie elementu byłoby prostsze.

<Border CornerRadius="10" BorderThickness="2" BorderBrush="Blue" Background="Red" Margin="2"> 
    <Label Content="Lorem ipsum" /> 
</Border>