I have a Tree View that looks like this:
The data from this tree view is coming from a ViewModel with nested objects. The classes of this objects looks like this. I changed some of the code for privacy purposes:
public class RegistroModel {
public ObservableCollection < ClassA > ClassA { get; set; };
}
public class ClassA {
public ObservableCollection < ClassB > ClassB { get; set; }
}
public class ClassB {
public ClassC ClassC { get; set; }
}
The xaml of this TreeView looks like this:
<TreeView ItemsSource="{Binding Registros}" TreeViewItem.Selected="TreeView_Selected" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type vm:RegistroModel}" ItemsSource="{Binding ClassA}">
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type entities:ClassA}" ItemsSource="{Binding ClassB}">
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type entities:ClassB}">
<TextBlock Text="{Binding ClassC.Name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
Now, what I want to do, is to wrap some HierarchichalDataTemplates within a expandable Label to look like this:
I want to wrap the HierarchicalDataTemplate of RegistroModel
with the label INGRESOS, the one corresponding to the ClassA
model with CAUSAS PENALES label and the one with ClassB
with DELITOS label. I don't know if I have to use Labels o TreeViewItems to wrap the HierarchicalDataTemplate.
Is there a way to do this without changing the ViewModel structure and only changing the XAML? What is the best and easiest way to do this?