How to create TreeView content programmatically?
We found one method SetItemSource() to create TreeView items, but how to use this method to create hierarchical collections?
Last edited by pmike on 07 Jul 2014, 16:20, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: How to crate TreeView content programmatically?
To correctly set TreeView's content from ItemsSource and using data templates, you will need HierarchicalDataTemplates, that are not implemented yet (please report it in the bugtracker to be notified of the progress on this feature).
So the only solution available right now to achieve what you want, is to iterate your data structures, and programmatically create a TreeViewItem for each data item and manually assign the appropriate DataTemplate. I could help with this code if required.
Code: Select all
<Grid.Resources>
...
<HierarchicalDataTemplate DataType="DataCategory" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Red"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="DataElement">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</Grid.Resources>
Re: How to crate TreeView content programmatically?
Thanks for the answer! We will combine data and XAML in TreeView representation.
Re: How to create TreeView content programmatically?
Anyway, HierarchicalDataTemplates must be implemented. Please, file a bug to track this feature if it is important for you.
Who is online
Users browsing this forum: No registered users and 17 guests