如何删除WPF网格单元之间的小边界?

如何删除WPF网格单元之间的小边界?,wpf,xaml,Wpf,Xaml,我有一个复杂的问题,我有一些“边界”。它们不是真正的边界,它们更像是某种显示背景的透明边界 我用一个非常简单的例子再现了这个问题 代码如下: <Window x:Class="TestBorder.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micro

我有一个复杂的问题,我有一些“边界”。它们不是真正的边界,它们更像是某种显示背景的透明边界

我用一个非常简单的例子再现了这个问题

代码如下:

<Window x:Class="TestBorder.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TestBorder"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" Background="Black">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock Text="A" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Grid.Row="1" Grid.Column="1" Background="Green"/>
        <TextBlock Text="B" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Grid.Row="1" Grid.Column="2" Background="Green"/>
        <TextBlock Text="C" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Grid.Row="2" Grid.Column="1" Background="Green"/>
        <TextBlock Text="D" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Grid.Row="2" Grid.Column="2" Background="Green"/>
    </Grid>
</Window>

(带或不带边距,带或不带对齐)

这就产生了:

这样做背景有点奇怪,但这只是为了重现我的问题


有什么原因让我得到这些边框吗?

只需将主网格上的
SnapsToDevicePixels
设置为
True

很好,谢谢!你知道为什么默认情况下不设置为true吗?@J4N不客气(:)。