我不确定发生了什么,但我猜有些东西覆盖FontSize
了粗体标签的选择。如果设置为 11 而不是 12,我可以获得与您的示例大致相同的间距FontSize
。我得到这个图像,顶部 2 个标签设置为FontSize
12,底部标签设置为FontSize
11:
使用这个:
应用程序.Xaml
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="Label" TargetType="{x:Type Label}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="10,0"/>
</Style>
<Style x:Key="LabelBold" TargetType="{x:Type Label}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="10,0"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
<Style x:Key="WindowStyle" TargetType="{x:Type Window}">
<Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
<Setter Property="FontFamily" Value="Calibri"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</Application.Resources>
</Application>
主窗口.xaml
Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Style="{StaticResource WindowStyle}">
<Grid>
<Label Style="{StaticResource Label}" Height="32" HorizontalAlignment="Left" Margin="10,10,0,0" Name="label1" VerticalAlignment="Top">This is a test of font-weight:</Label>
<Label Style="{StaticResource LabelBold}" Height="32" HorizontalAlignment="Left" Margin="10,30,0,0" Name="label2" VerticalAlignment="Top">This is a test of font-weight:</Label>
<Label Style="{StaticResource LabelBold}" Height="32" HorizontalAlignment="Left" Margin="10,50,0,0" FontSize="11" Name="label5" VerticalAlignment="Top">This is a test of font-weight:</Label>
</Grid>
</Window>