我想在我的项目中为我的树视图实现分层数据模板。 结构看起来应该是这样的:
- ManagedItems (RootItem)
- Department 1
-Client 1
- Feature 1
- Feature 2
-Client 2
- Feature 1
- Department 2
- Department 4
- Department 5
-Client 4
- Feature 1
- Department 3
-Client 3
- Feature 1
- Feature 2
- Feature 3
//Current class for datatype
public class Entries
{
public string Department { get; set; }
public string Client { get; set; }
// ?? How to implement a drive array and a feature array which will be displayed correctly in the treeview?
public ObservableCollection<Entries> Children { get; set; }
}
它在C#和WPF(.NET 4.0)中。 一些想法?
感谢。
答案 0 :(得分:1)
适用于您的型号的线框:
class ManagedItems {
IList<Department> Departments // TreeView.ItemsSource
}
class Department {// HierDT
IList<object> Children // HierDT.ItemsSource; (can either be Department or Client)
}
class Client {// HierDT
IList<Feature> Features // HierDT.ItemsSource
}
class Feature { } // normal DataTemplate
在Department
中定义Client
和HierDTs
Feature
以及DataTemplate
TreeView.Resources
。
注意Department.Children
是objects
。这没关系,因为当WPF“看到”Client
时,它会“膨胀”到相应的HierDT
(以及当它“看到”Department
时,它会膨胀到Department
已定义HierDT
)。