I have a viewmodel with ObservableCollection<PersonViewModel> on it. PersonViewModel.Name is what I want to show.
I want a tree bound and showing the person names, but I want a root node called "Person Root" (so one collapsible root with names under it)
-Person Root
+Greg
+Tom
etc.
Is this possible in xaml with data binding without modifying my viewmodel structure?
Hi,
Did you try something like the following XAML:
<igTree:XamWebTree x:Name="TestXamWebTree">
<igTree:XamWebTreeItem Header="Person Root" ItemsSource="{Binding}">
<igTree:XamWebTreeItem.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</igTree:XamWebTreeItem.ItemTemplate>
</igTree:XamWebTreeItem>
</igTree:XamWebTree>
HTH,
One caveot to the question, how can this be applied when using hierarchical templates? e.g. Persons->Jobs
nm got it, wrap the hierarchy stuff in
<ig:XamTreeItem Header="MyHeader" IsExpanded="True" ItemsSource="{Binding}">
and then
<ig:XamTreeItem.HierarchicalItemTemplate>
You would have to use our HierarchicalDataTemplate class and set the property HierarchicalItemTemplate on the XamWebTreeItem, for example:
<igTree:XamWebTreeItem.HierarchicalItemTemplate>
<ig:HierarchicalDataTemplate ItemsSource="{Binding Jobs}">
<ig:HierarchicalDataTemplate.ItemTemplate>
<TextBlock Text="{Binding Position}"/>
</ig:HierarchicalDataTemplate.ItemTemplate>
</ig:HierarchicalDataTemplate>
</igTree:XamWebTreeItem.HierarchicalItemTemplate>
In case you have further nested data, you would have to create template for each corresponding level, by either setting the HierarchicalItemTemplate or ItemTemplate (latter for leaf nodes).
Note also how we specify the collection of nodes for the next level of nest - by setting the corresponding HierarchicalDataTemplate.ItemsSource property.