我正在尝试TreeView
仅从具有各种属性的对象的未嵌套列表中设置代码。我设置了SortDescriptions
and GroupDescriptions
,但我不知道如何HierarchicalDataTemplate
配置CollectionViewSource
配置。
有人可以给我一个纯代码示例吗?
我有:
ObservableCollection<AnimalObject> myAnimals = new ObservableCollection<AnimalObject>();
myAnimals.Add(new AnimalObject("mammal","cat"));
myAnimals.Add(new AnimalObject("mammal","dog"));
myAnimals.Add(new AnimalObject("bird","canary"));
myAnimals.Add(new AnimalObject("bird","eagle"));
myAnimals.Add(new AnimalObject("reptile","snake"));
myAnimals.Add(new AnimalObject("reptile","lizard"));
myAnimals.Add(new AnimalObject("reptile","dragon"));
ListCollectionView view = CollectionViewSource.GetDefaultView(myAnimals) as ListCollectionView;
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
view.SortDescriptions.Add(new SortDescription("Category", ListSortDirection.Ascending));
view.SortDescriptions.Add(new SortDescription("AnimalName", ListSortDirection.Descending));
......而且当时几乎不知道该怎么做。我希望TreeView
显示可以扩展以显示动物的类别。
谢谢。