<Window
  x:Class="HierarchicalBinding.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="HierarchicalBinding"
  xmlns:local="clr-namespace:HierarchicalBinding">
  <Window.Resources>
    <local:Families x:Key="Families">
      <local:Family FamilyName="Stooge">
        <local:Family.Members>
          <local:People>
            <local:Person Name="Larry" Age="21">
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="In Charge" />
                  <local:Trait Description="Mean" />
                  <local:Trait Description="Ugly" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
            <local:Person Name="Moe" Age="22" >
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="Nice" />
                  <local:Trait Description="Ugly" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
            <local:Person Name="Curly" Age="23" >
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="Stupid" />
                  <local:Trait Description="Ugly" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
          </local:People>
        </local:Family.Members>
      </local:Family>
      <local:Family FamilyName="Addams">
        <local:Family.Members>
          <local:People>
            <local:Person Name="Gomez" Age="135" >
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="Rich" />
                  <local:Trait Description="Creepy" />
                  <local:Trait Description="Speaks French" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
            <local:Person Name="Morticia" Age="121" >
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="Rich" />
                  <local:Trait Description="Pale" />
                  <local:Trait Description="Likes French" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
            <local:Person Name="Fester" Age="137" >
              <local:Person.Traits>
                <local:Traits>
                  <local:Trait Description="Rich" />
                  <local:Trait Description="Stupid" />
                  <local:Trait Description="Ugly" />
                </local:Traits>
              </local:Person.Traits>
            </local:Person>
          </local:People>
        </local:Family.Members>
      </local:Family>
    </local:Families>

    <!--<DataTemplate DataType="{x:Type local:Family}">
      <TextBlock Text="{Binding Path=FamilyName}" />
    </DataTemplate>-->

    <HierarchicalDataTemplate DataType="{x:Type local:Family}"
      ItemsSource="{Binding Path=Members}">
      <TextBlock Text="{Binding Path=FamilyName}" />
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="{x:Type local:Person}"
      ItemsSource="{Binding Path=Traits}">
      <TextBlock>
        <TextBlock Text="{Binding Path=Name}" />
        (age: <TextBlock Text="{Binding Path=Age}" />)
      </TextBlock>
    </HierarchicalDataTemplate>

    <DataTemplate DataType="{x:Type local:Trait}">
      <TextBlock Text="{Binding Path=Description}" />
    </DataTemplate>

  </Window.Resources>

  <TreeView DataContext="{StaticResource Families}">
    <TreeViewItem ItemsSource="{Binding}" Header="Families" />
  </TreeView>
</Window>
