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

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

问题描述

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

是否有办法在数据绑定的WPF DataGrid中有一个虚拟的完全为空的行或某种其他分隔符?我讨厌不得不去一个未绑定的目录,将所有内容手动添加到数据集和所有内容中.我已经手动完成此操作,只是不想再经历一次.

解决方案

我假设您在源数据上具有某种Group属性

 公共类MyDataItem{公共字符串组{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)

这篇关于添加空&amp;“分隔符&amp;"行到数据绑定的WPF DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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