public partial class Window2 : Window
public Window2()
InitializeComponent();
this.DataContext = new List<Parent>() { Base.GetParent("Parent 1"), Base.GetParent("Parent 2") };
public class Base
public string Name { get; set; }
public bool IsExpanded { get; set; }
public static Parent GetParent(string name)
Parent p = new Parent() { Name = name };
p.Children.Add(new Child() { Name = "Child 1", GrandChildren = new ObservableCollection<GrandChild>() { new GrandChild() { Name = "Grandchild 1" } } });
p.Children.Add(new Child() { Name = "Child 2", GrandChildren = new ObservableCollection<GrandChild>() { new GrandChild() { Name = "Grandchild 1" } } });
p.Children.Add(new Child() { Name = "Child 3", GrandChildren = new ObservableCollection<GrandChild>() { new GrandChild() { Name = "Grandchild 1" } } });
return p;
public class Parent : Base
public ObservableCollection<Child> Children { get; set; }
public Parent()
this.Children = new ObservableCollection<Child>();
public class Child : Base
public ObservableCollection<GrandChild> GrandChildren { get; set; }
public Child()
this.GrandChildren = new ObservableCollection<GrandChild>();
public class GrandChild : Base
}