'WPF TreeView - Display a particular child node one level up in the hierarchy
I am showing an hierarchical data in WPF's TreeView. For a particular child node, i need to hide it's parent and show this childnode one level up.
eg: This is what my xaml looks like (followed the example provided here https://www.c-sharpcorner.com/article/populating-hierarchical-data-in-treeview-in-wpf-using-mvvm/):
<TreeView x:Name="MainTreeView" HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch" ItemsSource="{Binding Departments}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Positions}" DataType="{x:Type VM:Department}">
<Label Content="{Binding DepartmentName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Employees}" DataType="{x:Type VM:Position}">
<Label Content="{Binding PositionName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type VM:Employee}">
<Label Content="{Binding EmployeeName}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
It is currently displaying employees under position, and position under department.
for a particular position, I want to display the employees directly under department instead of the position (this looks silly, but the real world scenario is different and needs this hack).
If the position is "Architect", I want to display the employee names under Department. The "Architect" position will not be shown in the TreeView.
DotNet
|
|__Employee1
|__Employee2
|
|__TL
|
|__Employee1
|__Employee2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

