你好我是WPF新手,我创建了一个数据结构,我想在TreeView中显示我不同类型的对象,我有点困惑从哪里开始和如何 .
这就是我的数据结构:
public class Product {
public int ID;
}
public class ProductType1 : Product {
public double Length;
public List<Profile> Profiles = new List<Profile>();
public List<Item> Items = new List<Item>();
}
可以有更多的产品类型,但它们非常不同,只有一个共同的ID . 并且在TreeView中只能同时加载一个 .
public class Profile {
public String Name;
public List<Rectangles> Rectangles = new List<Rectangles>();
}
public class Rectangle {
public double K1;
public double K2;
}
public class Item {
public String Name;
public String Color;
}
之后TreeView应如下所示:
-ProductName
--Type: ProductType1
--ID: 1234
--Length: 5000
-Items
--Item1
--Item2
---Colour: blue
-Profiles
--Profile1
--Profile2
---Rectangle1
----K1: 55
----K2: 80
我现在的问题是:
1.当我想显示ProductType1时,如何实现数据绑定 . 我读了......关于HierarchicalDataTemplates . XAML会是什么样子,特别是TreeView绑定部分 . 我需要额外的ViewModels吗?
2.我如何结合具有共同ID的不同产品类型来实现数据绑定 . 我是否需要为每种产品使用不同的DataTemplates,如何选择它们 .
我希望你能帮助我,并为我提供一些有用的链接!