<!-- Window1.xaml.cs -->
<Window
  x:Class="ListBinding2.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:ListBinding2"
  Title="ListBinding"
  Height="325"
  Width="400">
  <Window.Resources>
    <local:People x:Key="Family">
      <local:Person Name="Tom" Age="11" />
      <local:Person Name="John" Age="12" />
      <local:Person Name="Melissa" Age="38" />
    </local:People>
    <!-- must be before DataTemplate so it can be found -->
    <!-- when creating the Foreground binding -->
    <local:AgeToForegroundConverter x:Key="ageConverter" />
    <DataTemplate DataType="{x:Type local:Person}">
      <TextBlock>
        <TextBlock Text="{Binding Path=Name}" />
        (age: <TextBlock Text="{Binding Path=Age}" Foreground="{Binding Path=Age, Converter={StaticResource ageConverter}}" />)
        <!--<Button Click="showButton_Click">Show</Button>-->
      </TextBlock>
    </DataTemplate>
  </Window.Resources>
  <Grid DataContext="{StaticResource Family}">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <ListBox Name="lb" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" Margin="5">
      <ListBox.GroupStyle>
        <x:Static Member="GroupStyle.Default"/>
        <!--<GroupStyle>
          <GroupStyle.HeaderTemplate>
            <DataTemplate>
              <TextBlock Background="Black" Foreground="White" FontWeight="Bold">
                <TextBlock Text="{Binding Name}" />
                (<TextBlock Text="{Binding ItemCount}" />)
              </TextBlock>
            </DataTemplate>
          </GroupStyle.HeaderTemplate>
        </GroupStyle>-->
      </ListBox.GroupStyle>
      <!--<ListBox.ItemTemplate>
        <DataTemplate>
          <TextBlock>
            <TextBlock Text="{Binding Path=Name}" />
            (age: <TextBlock Text="{Binding Path=Age}" Foreground="{Binding Path=Age, Converter={StaticResource ageConverter}}" />)
          </TextBlock>
        </DataTemplate>
      </ListBox.ItemTemplate>-->
    </ListBox>
    <TextBlock Grid.Row="1" Grid.Column="0" Margin="5" VerticalAlignment="Center">Name:</TextBlock>
    <TextBox Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding Path=Name}" />
    <TextBlock Grid.Row="2" Grid.Column="0" Margin="5" VerticalAlignment="Center">Age:</TextBlock>
    <TextBox Grid.Row="2" Grid.Column="1" Margin="5" Text="{Binding Path=Age}"
             Foreground="{Binding Path=Age, Converter={StaticResource ageConverter}}" />
    <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
      <Button Name="birthdayButton" Width="75" Margin="5">Birthday</Button>
      <Button Name="backButton" Width="75" Margin="5">&lt;</Button>
      <Button Name="forwardButton" Width="75" Margin="5">&gt;</Button>
    </StackPanel>
    <StackPanel Grid.Row="4" Grid.Column="1" Orientation="Horizontal">
      <Button Name="addButton" Width="75" Margin="5">Add</Button>
      <Button Name="sortButton" Width="75" Margin="5">Sort</Button>
      <Button Name="filterButton" Width="75" Margin="5">Filter</Button>
      <Button Name="groupButton" Width="75" Margin="5">Group</Button>
    </StackPanel>
  </Grid>
</Window>
