这篇MSDN文章利用本地WPF技术实现了TreeView/Grid混合的效果。它基于TreeView和Grid控件。它支持具有多列的树状视图,但不支持排序或过滤。
http://dlaa.me/blog/post/9898803
编辑:我最近集成了这段代码,它非常好用,可以给你想要的效果:http://www.codeproject.com/Articles/30721/WPF-TreeListView-Control
您是否考虑过使用 Xceed.Wpf.DataGrid ?
您可以在此处查看完整版本的演示:这里。
还有一个社区版,作为Extended WPF Toolkit™的一部分 - Ms-PL许可证
完整版功能列表
社区版功能列表
不幸的是,我找不到表格样式的编译。
P.S.
通过使用 Snoop(WPF Spy实用程序)和Visual Studio 2010(专业版)上的Spy++,我发现您在Watch、Local和Autos工具窗口中看到的TreeGrid被称为TREEGRID,它不是Wpf组件。(但我不确定它是什么)。
有趣的是,我发现断点工具窗口是通过并排使用两个组件 - SysTreeView32和SysListView32构建的。
我与Xceed没有关系:-)
编辑:
看来在两个版本中都可以实现层次结构,但只有在完整版中才存在主细节,而在社区版中只能使用分组来实现。
:-(
你可以尝试在TreeView的模板中使用特别对齐的共享Grid对象来伪造此显示...
然而,我不认为你在Visual Studio中看到的是WPF控件实现,因为它在Visual Studio 2008中也存在,很可能是自定义本地控件或自定义Windows Forms控件。
好消息是:如果你一定要拥有这种体验并且想要尽快实现...虽然这是一个完全的hack,但是:使用Windows Forms与你的WPF应用程序进行交互。
微软员工在'06年博客中发布了一个winforms TreeGridView
实现:
这个对我来说非常好用。 https://www.codeproject.com/Articles/30721/WPF-TreeListView-Control
public ITreeModel TreeModel
{
get => (ITreeModel)GetValue(TreeModelProperty);
set => SetValue(TreeModelProperty, value);
}
public static readonly DependencyProperty TreeModelProperty =
DependencyProperty.Register(
"TreeModel",
typeof(ITreeModel),
typeof(TreeList),
new PropertyMetadata(null, OnModelChanged));
private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var treeList = (TreeList) d;
treeList.Root.Children.Clear();
treeList.Rows.Clear();
treeList.CreateChildrenNodes(treeList.Root);
}
ObjectListView 对我来说看起来非常不错...
您可以通过按照这个教程(滚动到使用ViewModel进行虚拟分组部分)来在DataGrid中获得类似的行为。
教程的解决方案已经足够好了,但是当一些行被折叠时,滚动可能会变得很卡顿,并且其行为也不可预测。
更新:我改变了子项的隐藏方式。现在,我从绑定的ObservableCollection中删除了项目,而不是折叠行。现在滚动效果非常完美!
您正在寻找 TreeView
http://msdn.microsoft.com/zh-cn/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>
Microsoft.VisualStudio.Platform.WindowManagement.GenericPaneClientHwndHost
,但内部控件(Tree+Grid)并不是真正的WPF控件。这些可能是存储在Microsoft.VisualStudio.Platform.WindowManagement.dll附近的一些内部(和本地?)控件。 - itsho