i want to Display a treeview bound to a Model
It works but:
<TreeView ItemsSource="{Binding Items}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}" >
<Style.Triggers>
<Trigger Property="HasItems" Value="true">
<Setter Property="Focusable" Value="False"/>
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding SubNodes}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0"/>
<TextBlock Text="{Binding Text}" Grid.Column="1"/>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
I want to have three Templates : one for the rootitem , a second for the subnodes and a third for subnodes but alternative to the other template.
Its relatively simple.
Define three different types to which the tree is bound:
Construct them and add them to your ViewModel
Then use HierarchicalDataTemplate.DataType to designate the template for each: