Hierarchical Treeview
Posted: 14 Mar 2024, 11:40
Hi all,
I am trying to create a hierarchical treeview using a HierarchicalDataTemplate and a grouped list. The list is of type List<IGrouping<string, MyClass>> and the way I am binding the treeview to that list is the following:
But this is not working, I am only getting the first level in the Tree and there is no expander or children displayed. Is this supported? If not, how should I bind hierarchical data to a treeview?
Thanks!
I am trying to create a hierarchical treeview using a HierarchicalDataTemplate and a grouped list. The list is of type List<IGrouping<string, MyClass>> and the way I am binding the treeview to that list is the following:
Code: Select all
<TreeView ItemsSource="{Binding GroupedList}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding}">
<TextBlock Text="{Binding Key}" Margin="3 2" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<ContentControl>
<TextBlock Text="{Binding ItemName}"></TextBlock>
</ContentControl>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Thanks!