WPF - 边框和文本块 - 奇怪的行为

WPF - Border & TextBlock - Strange Behavior

我有这个非常简单的 XAML 标记

<Grid Margin="20">
    <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition Height="50"/>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Vertical" Grid.Row="0">
        <TextBlock Text="Hello World" FontSize="20"/>
        <Border BorderBrush="Black" BorderThickness="0.25"/>
    </StackPanel>
    <StackPanel Orientation="Vertical" Grid.Row="1">
        <TextBlock Text="Hello World" FontSize="19" />
        <Border BorderBrush="Black" BorderThickness="0.25"/>
    </StackPanel>
</Grid>

...代码隐藏文件中没有代码。

但结果很奇怪...,应用程序运行时,第一个堆栈面板中的边框变得蓬松,第二个堆栈面板中的边框清晰美观。

唯一的区别在于两个文本块,第一个文本块的字体大小为 20,第二个文本块的字体大小为 19。

那么是什么触发了第一个边框的蓬松...?

在您的网格中尝试 UseLayoutRounding="True"。

https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(System.Windows.FrameworkElement.UseLayoutRounding);k(VS.XamlEditor);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5.2)&rd=true

    <Grid Margin="20" UseLayoutRounding="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Vertical" Grid.Row="0">
            <TextBlock Text="Hello World" FontSize="20"/>
            <Border BorderBrush="Black" BorderThickness="0.25"/>
        </StackPanel>
        <StackPanel Orientation="Vertical" Grid.Row="1">
            <TextBlock Text="Hello World" FontSize="19" />
            <Border BorderBrush="Black" BorderThickness="0.25"/>
        </StackPanel>
    </Grid>