I am trying to display a simple parent/child treeview by reading the parent and child from a database. Do you have an example of reading from a database (i.e Northwind db Customer/Orders) and displaying that in a XamTree?
The data would come back from the database as
From other examples I have seen it seems I need to take that data and reformat it before binding to the xamtree. I have spent all day on this so an example would be great.
Thanks, Ken
HI,
I am just following up on this forum thread.
If you require further assistance regarding this issue, please let me know.
Sincerely, Matt Developer Support Engineer
One of experts worked on this sample for you
I have attached it to this thread
Sincerely,.
Matt Developer Support Engineer
Sorry, I mean to give a sample and clicked post....
Inside the tree give it a template for the Heirarchy:
<ig:HierarchicalDataTemplate ItemsSource="{Binding SubFolders}" Template="{StaticResource RootFolder}"> <ig:HierarchicalDataTemplate.HierarchicalItemTemplate> <ig:HierarchicalDataTemplate ItemsSource="{Binding SubFolders}" Template="{StaticResource SubFolder1}"/> </ig:HierarchicalDataTemplate.HierarchicalItemTemplate> </ig:HierarchicalDataTemplate> </ig:XamTree.HierarchicalItemTemplate>
The tree gets it's item source set to the parent collection, then the child collections are mapped as above. My children are called SubFolders. Then just set the template to a template like this in the Resources section of teh Xaml:
<DataTemplate x:Key="SubFolder1"> <StackPanel Orientation="Horizontal"> <Image Margin="0,0,5,0" Height="16" Width="16" Source="/ManagementModule;component/Images/folder16.png"/> <TextBlock Text="{Binding Description}" Foreground="Black"/> </StackPanel> </DataTemplate>
Works like a champ! You should be able to do this with any data source if it's parent child relationship is setup correctly.
-Jeff
How are you getting the data back? If you load the data into a collection where each parent object has a property for a child, you can just use a datatemplate to map it out. Not sure what object types you are dealing with? (Xml, collections, EF, etc)
-J