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

2019-02-05 15:22发布

I need something just like this:

alt text

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

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

I assume it has to be somewhere in the framework, since VS2010 is build in 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.

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

6条回答
对你真心纯属浪费
2楼-- · 2019-02-05 15:50

You are looking for the 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>
查看更多
别忘想泡老子
3楼-- · 2019-02-05 15:52

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

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.

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.

A Microsoft employee blogged a winforms TreeGridView implementation back in '06:

查看更多
够拽才男人
4楼-- · 2019-02-05 15:53

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

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

查看更多
家丑人穷心不美
5楼-- · 2019-02-05 15:53

ObjectListView seems quite good to me...

查看更多
放荡不羁爱自由
6楼-- · 2019-02-05 15:57

Have you considered Xceed.Wpf.DataGrid ?

You can see a Demo of Full Version here.

There's also a Community Edition as part of Extended WPF Toolkit™ - Ms-PL license

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

P.S.

  1. By using Snoop (WPF Spy utility) and Spy++ on Visual Studio 2010 (Professional edition), I've found that the TreeGrid you see inside Watch, Local, and Autos tool-windows, is called TREEGRID which is not a Wpf component. (But I'm not sure what it is).
    Interesting though, I've found that the Breakpoints tool-window was built by using two components side-by-side - SysTreeView32 and SysListView32

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

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

查看更多
该账号已被封号
7楼-- · 2019-02-05 16:00

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

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!

查看更多
登录 后发表回答