I want to bind multiple, different lists to a TreeView in WPF. I looked up some other solutiones but could not find any help for my problem. This answer is pretty close but not quite what I am looking for.
I tried the linked solution above but it only displays two levels in the TreeView. I can't figure out how to show the name of each list as parent in the TreeView.
My object I want to display looks like this:
public class LightDistributor
{
public string Description { get; set; }
// ...
public List<Field> Hardware { get; set; }
public List<Type> Inputs { get; set; }
public List<Type> Outputs { get; set; }
}
public class Field
{
public string Fieldname { get; set; }
// ...
}
public class Type
{
public string TypeDescription { get; set; }
// ...
}
And the XAML:
<TreeView ItemsSource="{Binding LightDistributors}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type data:LightDistributor}" ItemsSource="{Binding Hardware}">
<TextBlock Text="{Binding Description}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type data:Field}">
<TextBlock Text="{Binding Description}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
What I want my Treeview to look:
LightDistributor - LongFloor
| Hardware
- Field1
- Field2
- Field3
| Inputs
- InputTypeA
- InputTypeB
| Outputs
- OutputTypeY
- OutputTypeZ
What it currently looks:
LightDistributor - LongFloor
- Field1
- Field2
- Field3
Depending on the SelectedItem, a UserControl is displayed with more parameters.