c# - DataGrid WPF:中间的灰线
问题描述
正如您在我的屏幕截图中看到的,我的 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 也会影响这种行为。试图用网格替换它们,嵌套它们时也出现了同样的问题。我从头开始重写了所有内容,它开始工作,所以我猜一些属性是错误的,并且 DataGrid 可能对此非常敏感。仍然不知道究竟是什么属性导致了这种情况,但万一有人遇到类似问题:尽量简化到最大值!
推荐阅读
- python - 如何将 Matlab 结构(字典)加载为 Python 字典?
- postgresql - 检查 postgres 函数中的查询
- reactjs - 开玩笑的 axios.create.mockImplementation 的 axios.create 返回 undefined
- ios - 如何在 SwiftUI 中使子视图阴影从父视图中溢出?
- kotlin - Kotlin gradle 对它的项目主页感到困惑
- wso2 - 尝试使用 Gmail 连接器发送电子邮件时发生 FileNotFoundException
- html - 你能找出错误吗?我正在尝试调试代码,但我看不到错误
- jquery - 为什么我的脚本隐藏元素会有延迟?
- r - 如何使用ggplot中的interaction()创建两个子组的图(几个图的组合)
- ios - SwiftUI Stack Offset 在旋转时发生变化导致崩溃