在WPF的TreeView分组子对象 [英] Grouping child objects in WPF TreeView

查看:193
本文介绍了在WPF的TreeView分组子对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过它们是什么让我的树视图将类似项目的集合。为了保持通用的,我的对象层次结构可能看起来像这样:

I am trying to get my tree view to group a collection of similar items by what they are. To keep things generic, my object hierarchy could look like this:


  • 对象结果

    • 对象组#1结果

      • 项目#1(A型)

      • 项目#2(类型 A')

      • 物品#3(类型'b')

      • 物品#4(类型'b')

      • Objects
        • Object Group #1
          • Item #1 (Type 'A')
          • Item #2 (Type 'A')
          • Item #3 (Type 'B')
          • Item #4 (Type 'B')

          现在我的TreeView显示这些对象酷似对象模型,但我想这样做是插入为每个对象类型一个TreeView节点,以便它看起来是这样的:

          Right now my TreeView shows these objects exactly like the object model, but what I would like to do is insert a TreeView node for each object type so that it would look like this:


          • 对象结果

            • 对象组#1结果

              • A型结果

                • 物品#1

                • 物品#2


                • 物品#3

                • 物品#4

                我在一个类似的问题在这里看到了有人建议有两个独立的 HierarchicalDataTemplates 所以我创建了一个包含同类型的列表一个TreeView'对象组#1的水平,但是这是因为它真的很笨拙一些节点内部的完全独立的树视图。我也一直试图用一个 CollectionViewSource 来筛选出了每个类别的项目,但是这并不能帮我非常好,因为我无法弄清楚如何。显示他们

                I saw in a similar question here that someone recommended to have two separate HierarchicalDataTemplates so I created one for 'Object Group #1' level which contains a TreeView with a list of the types, but this is really clumsy since it is a whole separate TreeView inside of some nodes. I have also been trying to use a CollectionViewSource to filter out the items in each category, but this doesn't do me very much good since I can't figure out how to display them.

                我想我的问题归结为:我如何做一个 HierarchicalDataTemplate 组它的孩子吗?如果有人能在正确的方向指向我,我将不胜感激了很多。

                I guess my question boils down to this: How do I make a HierarchicalDataTemplate group it's children? If someone could point me in the right direction I would appreciate it a lot.

                我可以张贴一些代码,如果有人想看到的,但我真的只是想弄清楚如何做我想做的,所以我的代码只是一个非常简单的数据绑定TreeView的现在。

                I can post some code if anyone wants to see, but I am really just trying to figure out how to do what I want so my code is just a pretty straight forward databound treeview right now.

                推荐答案

                看看的this 文章。我敢肯定,它会帮助你。

                Take a look at this article by Mr. Sumi. I'm sure it will help you.

                这篇关于在WPF的TreeView分组子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆