添加空的“分隔符”行到数据绑定WPF DataGrid [英] Add empty "separator" row to databound WPF DataGrid
问题描述
有没有办法在数据绑定的WPF DataGrid中有一个虚拟的完全空行或其他类型的分隔符?我会讨厌去一个未绑定的,手动添加一个数据集和一切。我已经手动完成了,我只是不想再经历了。
我假设您的源数据具有某种组属性
public class MyDataItem
{
public string Group {get;组; } //< - 假设这样的东西存在
}
让你的DataGrid的 ItemsSource
成为 ICollectionView
并启用分组
然后,您可以将生成的组的样式看成空格(请参阅此处,了解如何到DataGrid中的样式组)
I have a databound DataGrid, and I want to have some kind of dummy rows to act as separators between various rows that I'm trying to somehow group together. However, even adding a new row by creating a new instance of the object (with no set-up, just calling an empty constructor) and adding it to the ObservableCollection seems to fill the cells that correspond to the int properties with 0.
Is there a way to have a dummy completely empty row or some other kind of separator in a databound WPF DataGrid? I would hate to have to go to an unbound one, adding everything manually to a dataset and everything. I've done this manually, I just don't want to have to go through that again.
I'm assuming you have some sort of Group property on your source data
public class MyDataItem
{
public string Group { get; set; } // <-- assuming something like this exists
}
Make your DataGrid's ItemsSource
be an ICollectionView
and enable Grouping
Then you can style the resulting groups to look like empty spaces (see here for an example of how to style groups in the DataGrid)
这篇关于添加空的“分隔符”行到数据绑定WPF DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!