Reputation: 11
I just want to create a treeview using binding in wpf. I have a class (ClassRoot) as root and I have 3 properties in root class of type ClassA
, ClassB
, ClassC
like the following,
class ClassRoot
{
public ClassA propClassA { get; set; }
public ClassB propClassB { get; set; }
public ClassC propClassC { get; set; }
}
each class having its own properties. It may have properties of type List
or Enum
, etc., like below,
class ClassA
{
public string Name { get; set; }
//Here ListOfValues is an enum
public ListOfValues listValues { get; set; }
public List<string> stringValues { get; set; }
}
like the above class, ClassB
and ClassC
also having the same structure. I want to show this in WPF treeview like the following,
each properties should be editable, properties of type List
or Enum
should be represented as ComboBox
in treeview.
I can use hierarchical data template, but I'm confusing to implement this multi level hierarchy.
How can I proceed with this?
Thank you,
Upvotes: 1
Views: 614
Reputation: 1769
<HierarchicalDataTemplate DataType = "{x:Type src:ClassRoot}"
ItemsSource = "{Binding Path=Divisions}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType = "{x:Type src:ClassA}"
ItemsSource = "{Binding Path=Teams}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType = "{x:Type src:ClassB}"
ItemsSource = "{Binding Path=Teams}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
Upvotes: 0