Hierarchical Treeview
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!
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: Hierarchical Treeview
Hi,
IGrouping is not supported by Noesis, to use a HierarchicalDataTemplate the list should contain the groups, and each group should contain a list of items that you can bind in the template ItemsSource:
IGrouping is not supported by Noesis, to use a HierarchicalDataTemplate the list should contain the groups, and each group should contain a list of items that you can bind in the template ItemsSource:
Code: Select all
public class ViewModel
{
public List<Group> GroupedList { get; }
}
public class Group
{
public string Key { get; set; }
public List<MyClass> ItemsList { get; }
}
public class MyClass
{
public string ItemName { get; set; }
}
Code: Select all
<TreeView ItemsSource="{Binding GroupedList}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ItemsList}">
<TextBlock Text="{Binding Key}" Margin="3,2" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemName}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Who is online
Users browsing this forum: Galilman and 5 guests