WPF:是否有内置的 TreeGrid / TreeListView?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2703209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:42:14  来源:igfitidea点击:

WPF: Is there a built-in TreeGrid / TreeListView?

wpfcontrolstreelistview

提问by John Gietzen

I need something just like this:

我需要这样的东西:

alt text

替代文字

(I need both the TreeView and the ListView aspects. That is, Hirearchy and Columns.)

(我需要 TreeView 和 ListView 方面。即 Hirearchy 和 Columns。)

But, I need it in WPF. is this something that is built in, or am I going to have to build it myself?

但是,我在 WPF 中需要它。这是内置的东西,还是我必须自己构建?

I assume it has to be somewhere in the framework, since VS2010 is build in WPF.

我认为它必须在框架中的某个地方,因为 VS2010 是在 WPF 中构建的。

Edit: I have managed to get some of the functionality that I want using a TreeView and some grids with their Columns bound to a Parent grid's columns, but there are too many quirks in the functionality.

编辑:我已经设法使用 TreeView 和一些网格获得了一些我想要的功能,它们的列绑定到父网格的列,但是功能中有太多的怪癖。

Edit 2: I still have as-of-yet not found a way to do this. Any ideas?

编辑 2:我仍然没有找到一种方法来做到这一点。有任何想法吗?

回答by gls123

This post on MSDN makes use of native WPF to achieve a TreeView/Grid hybrid. It is based on the TreeView and Grid controls. It supports a treeview with multiple columns, but does not support sorting or filtering

MSDN 上的这篇文章使用本机 WPF 来实现 TreeView/Grid 混合。它基于 TreeView 和 Grid 控件。它支持具有多列的树视图,但不支持排序或过滤

http://dlaa.me/blog/post/9898803

http://dlaa.me/blog/post/9898803

EDIT: I have recently integrated this code and it works very nicely, gives you exactly what you want: http://www.codeproject.com/Articles/30721/WPF-TreeListView-Control

编辑:我最近集成了这段代码,它工作得很好,给你你想要的:http: //www.codeproject.com/Articles/30721/WPF-TreeListView-Control

回答by itsho

Have you considered Xceed.Wpf.DataGrid?

你考虑过Xceed.Wpf.DataGrid吗?

You can see a Demo of Full Versionhere.

你可以在这里看到完整版的演示。

There's also a CommunityEdition as part of Extended WPF Toolkit? - Ms-PL license

作为扩展 WPF 工具包的一部分,还有一个社区版?- Ms-PL 许可证

List of the features in Full version
List of the features in Community Edition
Unfortunately, I couldn't find a table-styled compilation.

完整版
中的功能列表 Community Edition 中的功能列表
不幸的是,我找不到表格样式的汇编。

P.S.

聚苯乙烯

  1. By using Snoop(WPF Spy utility) and Spy++on Visual Studio 2010 (Professional edition), I've found that the TreeGridyou see inside Watch, Local, and Autostool-windows, is called TREEGRIDwhich is nota Wpf component. (But I'm not sure what it is).
    Interesting though, I've found that the Breakpointstool-window was built by using two components side-by-side - SysTreeView32and SysListView32

  2. I'm not related to Xceed in any way :-)

  1. 通过在 Visual Studio 2010(专业版)上使用Snoop(WPF Spy 实用程序)和Spy++,我发现您在WatchLocalAutos工具窗口中看到的TreeGrid称为TREEGRID,它不是Wpf 组件。(但我不确定它是什么)。 尽管关注的是,我发现断点工具窗口始建通过两个组件并排侧- SysTreeView32SysListView32

  2. 我与 Xceed 没有任何关系:-)

Edit:
It seems that Hierarchy can be achieved on both Version, but Master-Detailis only present in the Full version, and on the Community versionyou can get only by using Groups.
:-(

编辑:
似乎 Hierarchy 可以在两个版本上实现,但Master-Detail仅存在于Full 版本中,而在Community 版本上,您只能通过使用Groups来获得。
:-(

回答by Jeff Wilcox

You may be able to fake this display using specially-aligned shared Grid objects in your templates for TreeView...

您可以在 TreeView 的模板中使用特别对齐的共享 Grid 对象来伪造此显示...

However I don't believe the one you see in Visual Studio is actually a WPF control implementation, it was there in Visual Studio 2008 as well and is likely either a custom native control or custom Windows Forms control.

但是,我不相信您在 Visual Studio 中看到的实际上是 WPF 控件实现,它也存在于 Visual Studio 2008 中,并且可能是自定义本机控件或自定义 Windows 窗体控件。

Good news, though: if you must absolutely have this experience and want it soon... it's a total hack, but: use Windows Forms interop with your WPF app.

不过,好消息是:如果您必须绝对拥有这种体验并很快想要它......这完全是一种黑客行为,但是:使用 Windows 窗体与您的 WPF 应用程序互操作。

A Microsoft employee blogged a winforms TreeGridViewimplementation back in '06:

一位微软员工TreeGridView在 06 年在博客上写了一个 winforms实现:

回答by TigrouMeow

ObjectListViewseems quite good to me...

ObjectListView对我来说似乎很好......

回答by Pakman

You can somewhat obtain this behavior with the DataGrid by following this tutorial(scroll the the Fake grouping with the help of the ViewModelsection).

通过遵循本教程在 ViewModel部分的帮助下滚动Fake 分组),您可以在某种程度上使用 DataGrid 获得这种行为。

The tutorial's solution works well enough, but scrolling can get laggy and it's behavior unpredictable when some rows are collapsed.

本教程的解决方案运行良好,但滚动会变得滞后,并且在折叠某些行时其行为不可预测。

Update: I changed how the children are hidden. Instead of collapsing rows, I removed items in the bound ObservableCollection. Now scrolling works perfectly!

更新:我改变了孩子们的隐藏方式。我没有折叠行,而是删除了绑定 ObservableCollection 中的项目。现在滚动完美!

回答by rasx

You are looking for the TreeViewhttp://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx:

您正在寻找TreeViewhttp://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Page.Resources>
        <XmlDataProvider x:Key="StaticXml" XPath="root/foo">
            <x:XData>
                <root xmlns="">
                    <foo a="_File">
                        <foo a="New">
                            <foo a="_Project..." />
                            <foo a="_Web Site..."/>
                        </foo>
                        <foo a="C_lose"/>
                        <foo a="E_xit"/>
                    </foo>
                    <foo a="_Edit">
                        <foo a="Cu_t"/>
                        <foo a="_Copy"/>
                        <foo a="_Paste"/>
                    </foo>
                </root>
            </x:XData>
        </XmlDataProvider>
        <HierarchicalDataTemplate x:Key="MenuTemplate" ItemsSource="{Binding XPath=foo}">
            <AccessText Text="{Binding XPath=@a}"/>
        </HierarchicalDataTemplate>
    </Page.Resources>
    <StackPanel>
        <TreeView
                ItemsSource="{Binding Source={StaticResource StaticXml}}"
              ItemTemplate="{StaticResource MenuTemplate}"/>
    </StackPanel>
</Page>