Dưới đây là một ví dụ .....
<!-- Create a TreeView, and have it source data from
the AnimalCategories collection -->
<TreeView ItemsSource="{x:Static local:Window1.AnimalCategories}">
<!-- Specify the template that will display a node
from AnimalCategories. I.e., one each for “Amphibians”
and “Spiders” in this sample. It will get its nested
items from the "Animals" property of each item -->
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Animals}">
<!-- Display the AnimalCategory by showing it's Category string -->
<TextBlock FontWeight="Bold" Text="{Binding Path=Category}" />
<!-- Specify the nested template for the individual Animal items
that are within the AnimalCategories. E.g. “California Newt”, etc. -->
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
mã này là từ here nó có thể là hữu ích hơn cho bạn để đọc bài viết đó, tôi đang suy nghĩ.
Nguồn
2010-11-10 23:25:21
Cảm ơn người đàn ông, tôi sẽ thử ngay bây giờ. –
Thực sự xin lỗi tôi không thể làm việc này trong xaml, chỉ hoạt động trong mã. Vì vậy, những gì tôi sử dụng là: Đối với "{Binding Path = Animals}", tôi đã sử dụng {Binding Path = Categories}. Đối với {Binding Path = Category} sử dụng tương tự, như tôi nghĩ nó có nghĩa là gõ tên của loại, và cho "{Binding Path = Name}", được sử dụng giống nhau, nghĩ rằng đây là thành viên sẽ được hiển thị. –