简体   繁体   English

WPF与TreeView绑定

[英]TreeView Binding with WPF

I'm attempting to create a TreeView with a specific structure. 我正在尝试创建具有特定结构的TreeView。 I know how to create a TreeView and Bind data with a HierarchicalDataTemplate however I am struggling with how to design my template correctly. 我知道如何创建TreeView并使用HierarchicalDataTemplate绑定数据,但是我在努力正确地设计模板而苦苦挣扎。

The information I want to display to the user will look like this: ClassA ---ClassB ---ClassB ---ClassB ClassA ---ClassB ---ClassB ClassA ---ClassB 我要显示给用户的信息将如下所示:ClassA --- ClassB --- ClassB --- ClassB ClassA --- ClassB --- ClassB ClassA --- ClassB

In other words - I'll have a collection of ClassA which I would see as being a: 换句话说-我将拥有ClassA的集合,我将其视为:

public ObservableCollection<ClassA> ClassAItems

And I want ClassA to hold a collection of ClassB thus: 我希望ClassA这样持有ClassB的集合:

public ObserverableCollection<ClassB> ClassBItems

Any suggestions on how to get this set up? 关于如何进行此设置的任何建议?

I've resolved my own issue by using inheritance. 我已经通过使用继承解决了自己的问题。 I've created a base class that both ClassA and ClassB inherit which contains the Models/Header/Tooptip properties. 我创建了一个同时继承ClassA和ClassB的基类,其中包含Models / Header / Tooptip属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM