如何将TreeView绑定到Uncategory? [英] How to binding TreeView to Unlimit Category?

查看:68
本文介绍了如何将TreeView绑定到Uncategory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的课程:

I have a class like this:

public class EmpCtg
{
	public int ID { get; set; }
	public string Name { get; set; }
	public EmpCtg Parent { get; set; }
}


该课程的收藏:


Collection of this class:

List<EmpCtg> ListEmpCtg = //....get list<empctg>
</empctg>


我想将ListEmpCtg绑定到TreeView,并显示如下所示:


I want binding ListEmpCtg to TreeView, and show look like this:

EmpolyeeCategory
|
---------Ctg1
|
|
---------Ctg2
|          |
|          |
|          --------Ctg3
|          |
|          |
|          --------Ctg4
|                    |
|                    |
|                    --------Ctg5
.
.
.


我知道我可以手工编写代码,但是我想知道是否使用DataTemplate?

我该怎么办?

谢谢!


I know that I can write in the code by hand, but I would like to know whether to use DataTemplate?

What should I do?

Thanks!

推荐答案



到目前为止,我从未使用过TreeView,但是在学习时,我遇到了一些示例.他们都使用了数据对象,这些数据对象包含指向该对象的孩子的链接(与您的类相反).这样的结构可以绑定到HierarchicalDataTemplate中的"ItemsSource"属性.对我来说,使用面向儿童"的数据看起来非常合理,因为树是从顶部访问的.

如果您的问题不仅基于理论兴趣,您可以考虑将数据存储在
中 X(ml)文档(或任何其他拟合结构)并按此处所示使用它 [ ^ ].也许添加另一个成员就足够了
Hi,

until now I''ve never used a TreeView, but while learning, I came across a few samples. They all used data objects that contained a link to the object''s children (opposite to your class). Such a structure can be bound to the "ItemsSource"-property in a HierarchicalDataTemplate. To me it looks very reasonable to use ''child-oriented'' data, as the tree is accessed from the top.

If your question was not only based on theoretical interest, you might consider storing your data in an
X(ml)Document (or any other fitting structure) and use it as shown here[^]. Maybe it''s sufficient to add another member
public List<EmpCtg> Children;


上你的课(就像我说的,我自己从来没有用过).

或者,您可以查看简化WPF TreeView ... [


to your class (as I said, I never used it myself).

Or you take a look at Simplifying the WPF TreeView...[^] from Josh Smith here on CodeProject (worth the time - anyway).

Cheers
Jürgen


这篇关于如何将TreeView绑定到Uncategory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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