Модель:
public class Person
{
public Person(string name)
{
this.Name = name;
}
public string Name { get; set; }
public ObservableCollection<Person> Childs { get; set; }
}
XAML:
<TreeView ItemsSource="{Binding Path=Persons}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:Person}" ItemsSource="{Binding Childs}">
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
Главное окно:
public partial class MainWindow : Window
{
public MainWindow()
{
Persons = new ObservableCollection<Person>();
Persons.Add(new Person("Name1"));
Persons[0].Childs = new ObservableCollection<Person>();
Persons[0].Childs.Add(new Person("Child1"));
Persons[0].Childs.Add(new Person("Child2"));
Persons[0].Childs[0].Childs = new ObservableCollection<Person>();
Persons[0].Childs[0].Childs.Add(new Person("Child1 Child2"));
InitializeComponent();
this.DataContext = this;
}
public ObservableCollection<Person> Persons { get; private set; }
}
Надеюсь, это поможет.