pmike
Topic Author
Posts: 28
Joined: 31 Oct 2012, 09:29

How to create TreeView content programmatically?

07 Jul 2014, 12:56

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.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: How to crate TreeView content programmatically?

07 Jul 2014, 13:13

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).
    <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>
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.
 
pmike
Topic Author
Posts: 28
Joined: 31 Oct 2012, 09:29

Re: How to crate TreeView content programmatically?

07 Jul 2014, 13:44

Thanks for the answer! We will combine data and XAML in TreeView representation.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to create TreeView content programmatically?

10 Jul 2014, 23:48

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 2 guests