绑定线性列表到分层树视图
class MyItem
{
public long ID;
public string Name;
public long? ParentID;
public MyItem(long id, string name, long? parent)
{
ID = id;
Name = name;
ParentID= parent;
}
}
List<MyItem> myItemList = new List<MyItem>();
myItemList.Add(new MyItem(1, "Item1", null));
myItemList.Add(new MyItem(2, "Item1", 1));
myItemList.Add(new MyItem(3, "Item1", 1));
myItemList.Add(new MyItem(4, "Item1", 5));
myItemList.Add(new MyItem(5, "Item1", null));
myItemList.Add(new MyItem(6, "Item1", 3));
myItemList.Add(new MyItem(7, "Item1", null));
我想使用 XAML 将 myItemList 绑定到 WPF 树视图以获得这样的视图。
1
|--2
|--3
|--6
5
|--4
7
class MyItem
{
public long ID;
public string Name;
public long? ParentID;
public MyItem(long id, string name, long? parent)
{
ID = id;
Name = name;
ParentID= parent;
}
}
List<MyItem> myItemList = new List<MyItem>();
myItemList.Add(new MyItem(1, "Item1", null));
myItemList.Add(new MyItem(2, "Item1", 1));
myItemList.Add(new MyItem(3, "Item1", 1));
myItemList.Add(new MyItem(4, "Item1", 5));
myItemList.Add(new MyItem(5, "Item1", null));
myItemList.Add(new MyItem(6, "Item1", 3));
myItemList.Add(new MyItem(7, "Item1", null));
I want to bind the myItemList to a WPF treeview with XAML inly to get a view like this.
1
|--2
|--3
|--6
5
|--4
7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我解决问题的方法。
我需要有 2 个类:
1)
LinqToObjectsExtensionMethods
:2)
HierarchyNode
:我有
List; myItemList;
然后
Here is how I solved it.
I need to have 2 classes:
1)
LinqToObjectsExtensionMethods
:2)
HierarchyNode<T>
:I have the
List<MyItem> myItemList;
Then