DataGrid WPF:中间的灰线

DataGrid WPF: gray line in the middle

如您在我的屏幕截图中所见,我的 DataGrid 中间有一条灰色线,位于网格的第 20 个元素之后。它只有在有足够数据时才会发生,并且不会随元素移动:它只是在滚动时停留在那里。

我一直在搜索可以激活它的选项,但找不到类似的东西。可能我的搜索词有误,所以我才问。

我尽量简化了,这是我的XAML:

<Grid Margin="5,10,5,5" MaxHeight="600" MinWidth="800" MaxWidth="800">
    <DataGrid Name="DataGridTest" GridLinesVisibility="None">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
        </DataGrid.Columns>
        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            </Style>
        </DataGrid.CellStyle>
    </DataGrid>
</Grid>

这是我的 C#:

public class TestData
{
    public string Name { get; set; }
}

public partial class Hello : Window
{
    public Hello()
    {
        InitializeComponent();

        List<TestData> testData = new List<TestData>();

        for (var i = 0; i < 25; i++)
            testData.Add(new TestData { Name = ("name" + i) });

        DataGridTest.ItemsSource = testData;
    }
}

我在桌面 WPF 应用程序上使用 .NET 5。

感谢任何可能有帮助的见解!

好的,所以在摆弄了几个小时之后,这肯定是尺寸问题。我不知道如何,但我有一些嵌套的 StackPanels 也影响了这种行为。尝试用Grids替换,嵌套时出现同样的问题。我从头开始重写并开始工作,所以我猜有些属性是错误的,DataGrid 可能对此非常敏感。仍然不知道究竟是什么属性导致了这种情况,但如果有人有类似的问题:尽量简化到最大!