I have a WPF TreeView that is bound to a list of objects that has several lists in each of them.
public List<OwnerClass> OwnerClasses {get; set;}
public class OwnerClass
{
public List<SomeObject> SomeObjects { get; set; }
public List<OtherObject> OtherObjects { get; set; }
}
I am looking to find a way to show both lists as children of the parent.
Like this:
> Owner1
|
+ SomeObject 1
+ SomeObject 2
+ SomeObject 3
+ OtherObject 1
+ OtherObject 2
+ OtherObject 3
+ OtherObject 4
> Owner2
|
+ SomeObject 1
+ SomeObject 2
+ SomeObject 3
+ OtherObject 1
+ OtherObject 2
+ OtherObject 3
+ OtherObject 4
I want the treeview functionallity, but I want the child lists side by side. (And each one as a tree view, because they in turn have lists.)
Is this possible?
You need two things really to do this easily. The first has been demonstrated nicely by @DLeh, although I'd recommend using the
ObservableCollection<T>
class rather than theList<T>
class when using WPF.The second thing you need is a
HierarchicalDataTemplate
. It's like an ordinaryDataTemplate
, but it allows you to set a source for the child nodes:You can find out more from the
HierarchicalDataTemplate
Class page on MSDN.