添加空的“分隔符”行到数据绑定WPF DataGrid [英] Add empty "separator" row to databound WPF DataGrid

查看:166
本文介绍了添加空的“分隔符”行到数据绑定WPF DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据绑定的DataGrid,我想要有一些虚拟行作为分隔符,我想要以某种方式组合在一起的各行之间的分隔符。然而,即使通过创建对象的新实例(没有设置,只是调用一个空构造函数)并将其添加到ObservableCollection中也可以添加新行,似乎将与int属性对应的单元格填充为0。 p>

有没有办法在数据绑定的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆