具有 TreeView 类型层次结构的 WPF DataGrid
是否有可能有一个纯粹的分层wpf数据网格?现在,互联网上讨论了 3 种可能的解决方案...
- GroupStyle
- TreeListView 而不是 DataGrid
- 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 ...
- GroupStyle
- TreeListView instead of DataGrid
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于可以实现这个了。代码太大,无法发布。但如果有人正在寻找解决方案,请给我发送电子邮件。
基本上我做了以下事情...
INotifyPropertyChanged
并通过基类遵循额外的属性..Parent =>该项目是其子项目的父项目。只读。
拥有层次结构 =>当层次结构子级为 null 或为空时为 False。可写。
IsItemVisible =>;当前能见度。可写。
IsBranchVisible =>;如果任何祖先具有 IsExpanded = false 或 IsItemVisible = false,则为 False。只读但可通知。
已展开 =>如果该项目被扩展。可写。
沃拉!它的作用就像魅力一样。由于 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...
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.
Voala! It works like charm. Fast due to PLINQ.