具有TreeView类型层次结构的WPF DataGrid [英] WPF DataGrid with TreeView type hierarchy

查看:359
本文介绍了具有TreeView类型层次结构的WPF DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有一个纯粹的分层wpf数据网格?现在在互联网上讨论了3种可能的解决方案...

Is it possible to have a pure hierarchical wpf data grid? Now there are 3 possible solutions dicussed over the internet ...


  1. GroupStyle

  2. TreeListView而不是DataGrid

  3. RowDetailsTemplate

现在在我的案例中,这3个都没有用,因为它们每个都有局限性。

Now all 3 are not useful in my case as they each have limitations.

GroupStyle 提供分组的行演示者,但其父项只是 GroupItem 。这是我的数据源不同的地方。在我的情况下,分组项目的父项将是同一类型的项目。

GroupStyle provides grouped row presenters but their parent is simply GroupItem. This is where my data source is different. In my case the parent of the grouped items will be of the same type of item.

例如文件夹类具有 List< Folders>儿童。因此,子文件夹的父文件夹本身就是文件夹类型。

e.g. Folder class has List<Folders> children. So the parent of child folders is of type Folder itself.

RowDetailsTemplate 需要我托管另一个绑定到 Children 的数据网格,但这将意味着它将拥有自己的列标题,而我想要的是 share 与父DataGrid相同的列视图,就像它们在 TreeListView 中所做的一样。

RowDetailsTemplate would need me to host another datagrid that is bound to Children, but that would mean it would have its own column headers and what I want is the children to share the same column view of the parent DataGrid, just like they do in TreeListView.

对于 TreeListView ,那是我现在正在使用的东西,但是它的问题是...

And for TreeListView, thats what I am using right now, but its problem is ...

它松动了虚拟化和它不是数据网格

:-)

我在想像一些附加的行为那样,可以切换数据网格的层次结构视图,例如...

I was thinking like some attached behavior that toggles the hierarchy view for the data grid like...

  <DataGrid HierarchicalBehavior.HierarchyPath="Children" ... />

其中儿童是类型 IEnumerable 在每个项目下。

Where Children is a property of type IEnumerable under each item.

我希望你们能理解我的意思。

I hope you guys understand what I am getting at.

有什么想法吗?

推荐答案

我最终可以实现这一点。该代码太大,无法发布。但是,如果有人在寻找解决方案,请向我发送电子邮件。

I could implement this finally. The code is too big to post. But if anyone's looking for the solution, do send an email to me.

基本上,我做了以下事情...

Bascially I did the following things...


  1. 我使用了将项目层次结构快速平化为平面列表的方法。

  2. 绑定到WPF数据网格的每个项目我都实现了 INotifyPropertyChanged 并通过基类遵循其他属性..

  1. I used the quick flattening of hierarchy of item into flat list.
  2. Each item bound to the WPF data grid I implemented INotifyPropertyChanged and also following extra properties via a base class ..

父级 > =>此项目作为子项目的父项目。

Parent => Parent item which this item is child for. Readonly.

HasHierarchy =>如果层次结构子级为null或为空,则为False。

HasHierarchy => False when hierarchy children is null or empty. Writeable.

IsItemVisible =>当前可见性。

IsItemVisible => Current Visibility. Writeable.

IsBranchVisible =>如果任何祖先的IsExpanded = false或IsItemVisible = false,则为False。只读,但可通知。

IsBranchVisible => False if any ancestor has IsExpanded = false or IsItemVisible = false. ReadOnly but notifyable.

已扩展 =>如果该项已展开。

IsExpanded => If the item is expanded. Writeable.

3. I put a PLINQ call to filter the `IsBranchVisible` property as true, of all children whenever any descenden's `IsExpanded` property is **toggled**.

哇!它就像魅力。由于PLINQ,速度很快。

Voala! It works like charm. Fast due to PLINQ.

这篇关于具有TreeView类型层次结构的WPF DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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