How do I structure the xaml for a TreeView so that the output looks like this:
Classes
public class SchoolData
{
public Contract Permanent { get; set; }
public Contract Temporary { get; set; }
}
public class Contract
{
public ObservableCollection<Teacher> Teachers { get; set; }
public ObservableCollection<Assistant> Assistants { get; set; }
public ObservableCollection<Building> Buildings { get; set; }
}
public class Teacher
{
public string Name { get; set; }
public int ParkingPlaceNumber { get; set; }
}
public class Assistant
{
public string Name { get; set; }
public int RoomNumber { get; set; }
}
public class Building
{
public string Name { get; set; }
public int NumberOfRooms { get; set; }
}
I think I need 6 separate TreeView
s for each of the six lists that I want to display. I have tried the following, but all I get are object names and I do not get headers or heirarchical views.
<TreeView ItemsSource="{Binding SchoolData.Permanent.Teachers}" />
<TreeView ItemsSource="{Binding SchoolData.Permanent.Assistants}" />
<TreeView ItemsSource="{Binding SchoolData.Permanent.Buildings}" />
<TreeView ItemsSource="{Binding SchoolData.Temporary.Teachers}" />
<TreeView ItemsSource="{Binding SchoolData.Temporary.Assistants}" />
<TreeView ItemsSource="{Binding SchoolData.Temporary.Buildings}" />
What should the xaml look like to achieve the needed tree view?
<TreeView>
<TreeViewItem Header="Permanent" IsExpanded="True">
<TreeViewItem Header="Teachers" ItemsSource="{Binding SchoolData.Permanent.Teachers}"/>
<TreeViewItem Header="Buildings" ItemsSource="{Binding SchoolData.Permanent.Buildings}"/>
</TreeViewItem>
<TreeViewItem Header="Temporary" IsExpanded="True">
<TreeViewItem Header="Teachers" ItemsSource="{Binding SchoolData.Temporary.Teachers}"/>
<TreeViewItem Header="Buildings" ItemsSource="{Binding SchoolData.Temporary.Buildings}"/>
</TreeViewItem>
</TreeView>