Wpf 带网格的XAML*运算符的间距问题

Wpf 带网格的XAML*运算符的间距问题,wpf,xaml,Wpf,Xaml,所以,我只是想了解为什么我的WPF应用程序中会出现这种情况,因为它似乎在添加一个“空格”或一条模糊的线条,而我并不需要它 我有以下XAML <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfApplication3.MainWindow" x:Name="Win

所以,我只是想了解为什么我的WPF应用程序中会出现这种情况,因为它似乎在添加一个“空格”或一条模糊的线条,而我并不需要它

我有以下XAML

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication3.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
<Grid x:Name="LayoutRoot" ShowGridLines="False" Grid.Row="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>          
    </Grid.RowDefinitions>
    <Border Grid.Row="0"  CornerRadius="10,10,0,0" Height="10" Background="Black"/>
    <Border Grid.Row="1"  Background="Black">

    </Border>           
    <Border Grid.Row="2" CornerRadius="0,0,10,10" Height="10" Background="Black"/>
</Grid>
<StackPanel Grid.Row="1">
    <Button>Some Button</Button>
</StackPanel>
</Grid>

一些按钮

这将呈现以下窗口

问题是,如果您仔细查看最后一行连接器,您将看到一条微弱的灰线


但是,如果我用固定像素大小(即,
)替换内网格上的
,则该行将消失。为什么当我使用*值时,它似乎添加了这个“灰线”/“空格”?

对我来说,它看起来像是布局舍入问题。如果您使用的是WPF 4,请尝试在外部网格上设置
UseLayoutRounding=“true”
。否则,请查看
SnapToDevicePixels


我认为问题在于抗锯齿

  • 你的影响
  • SnapsToDevicePixels=“True”
  • UseLayoutRounding=“False”
  • RenderOptions.EdgeMode=“别名”

  • 谢谢Nicholas,两个答案都有效,我对你的反馈意见投了更高的票!