wpf边框比标签大得多

时间:2017-04-04 10:46:59

标签: c# wpf xaml label

我正试图在标签周围加上边框。但边界似乎有一些填充或边距,并没有接近标签。

 <Style x:Key="ArithmeticBorder" TargetType="Border">
            <Setter Property="BorderBrush" Value="Blue" />
            <Setter Property="BorderThickness" Value="6" />
            <Setter Property="CornerRadius" Value="6" />
            <Setter Property="Grid.Row" Value="4"/>
            <Setter Property="Grid.Column" Value="0"/>
        </Style>
 <Border Style="{StaticResource ArithmeticBorder}">
        <Label Content="Arithmetic" 
           HorizontalAlignment="Left" 
           Foreground="DarkBlue"
           Background="Yellow"
           FontStyle="Oblique"
           FontSize="16"
           FontFamily="Comic"
           Height="58.012" 
           Width="100"
           Margin="0,23.2,0,0"            
           VerticalAlignment="Top" 
           HorizontalContentAlignment="Center"
           VerticalContentAlignment="Center"
           />

2 个答案:

答案 0 :(得分:5)

删除Margin的{​​{1}},HorizontalAlignmentWidth属性:

Label

enter image description here

答案 1 :(得分:0)

除了删除 MarginHeight 属性之外,还向 Padding="0" 添加属性 Label。这是因为 Padding 的默认 Label 值为 5。

<Border Style="{StaticResource ArithmeticBorder}" Grid.Column="0" Grid.Row="0">
    <Label Content="Arithmetic" 
        HorizontalAlignment="Left" 
        Foreground="DarkBlue"
        Background="Yellow"
        FontStyle="Oblique"
        FontSize="16"
        FontFamily="Comic"
        Width="100"         
        VerticalAlignment="Top" 
        HorizontalContentAlignment="Center"
        VerticalContentAlignment="Center"
        Padding="0"/>
</Border>
相关问题