具有 TreeView 类型层次结构的 WPF DataGrid

发布于 2024-12-09 04:36:05 字数 967 浏览 0 评论 0原文

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

  1. GroupStyle
  2. TreeListView 而不是 DataGrid
  3. RowDetailsTemplate

现在,这 3 个解决方案在我的情况下都没有用,因为它们都有局限性。

GroupStyle 提供分组行呈现器,但它们的父级只是 GroupItem。这就是我的数据源不同的地方。就我而言,分组项目的父项将属于同一类型的项目。

例如 Folder 类有 List;孩子们。因此子文件夹的父文件夹本身就是 Folder 类型。

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

对于TreeListView,这就是我现在正在使用的,但它的问题是......

它失去了虚拟化并且它不是数据网格

:-)

我的想法就像一些附加行为切换数据网格的层次结构视图,例如...

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

其中 Children 是每个项目下的 IEnumerable 类型的属性。

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

有什么想法吗?

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 instead of DataGrid
  3. RowDetailsTemplate

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

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.

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

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.

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

It looses virtualization and it is not a datagrid

:-)

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

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

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

I hope you guys understand what I am getting at.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉默的熊 2024-12-16 04:36:05

我终于可以实现这个了。代码太大,无法发布。但如果有人正在寻找解决方案,请给我发送电子邮件。

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

  1. 我使用了将项目层次结构快速扁平化为平面列表的方法。
  2. 我实现了绑定到 WPF 数据网格的每个项目 INotifyPropertyChanged 并通过基类遵循额外的属性..

Parent =>该项目是其子项目的父项目。只读。

拥有层次结构 =>当层次结构子级为 null 或为空时为 False。可写。

IsItemVisible =>;当前能见度。可写。

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

已展开 =>如果该项目被扩展。可写。

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,速度很快。

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. 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 => False when hierarchy children is null or empty. Writeable.

IsItemVisible => Current Visibility. Writeable.

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**.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文