<Window x:Class="ListBoxBinding_Sample5.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ListBoxBinding_Sample5"
        xmlns:local2="clr-namespace:PersonLibrary2;assembly=PersonLibrary2"
        mc:Ignorable="d"
        Title="ListBoxBinding_Sample5" Height="300" Width="450">
    <Window.Resources>
        <local:PersonConverter x:Key="pConv" />
        <Style TargetType="Button">
            <Setter Property="Width" Value="100" />
            <Setter Property="Margin" Value="6" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="3 6 6 3" />
            <Setter Property="Grid.Column" Value="1" />
        </Style>
        <Style TargetType="Label">
            <Setter Property="Foreground" Value="White" />
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
    </Window.Resources>
    <Window.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="White" Offset="1"/>
        </LinearGradientBrush>
    </Window.Background>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <ListBox Name="listbox1" Margin="5" AlternationCount="2" HorizontalContentAlignment="Stretch">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Background" Value="LightBlue" />
                        <Setter Property="Margin" Value="1" />
                        <Setter Property="Padding" Value="0" />
                        <Setter Property="BorderBrush" Value="Gray" />
                        <Setter Property="BorderThickness" Value="1" />
                        <Style.Triggers>
                            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                <Setter Property="Background" Value="LightGray" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Foreground" Value="DarkBlue" />
                                <Setter Property="FontWeight" Value="Bold" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>

                <ListBox.ItemTemplate>
                    <DataTemplate DataType="{x:Type local2:Person}">
                        <Grid Name="grid1">
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Name="tbName" Margin="4 0 0 0">
                                <TextBlock.Text>
                                    <MultiBinding Converter="{StaticResource pConv}">
                                        <Binding Path="LastName" />
                                        <Binding Path="FirstName" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <TextBlock Margin="4 0 0 0" Name="tbAge" Grid.Row="1" Text="{Binding Age}" Foreground="Black"/>
                            <TextBlock Margin="4 0 0 0" Name="tbCity" Grid.Row="2" Text="{Binding City}" Foreground="Black"/>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Pension}" Value="True">
                                <Setter Property="Background" Value="DarkBlue" TargetName="grid1" />
                                <Setter Property="Foreground" Value="White" TargetName="tbName" />
                                <Setter Property="Foreground" Value="White" TargetName="tbAge" />
                                <Setter Property="Foreground" Value="White" TargetName="tbCity" />
                            </DataTrigger>
                        </DataTemplate.Triggers>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <Grid Grid.Column="1" DataContext="{Binding SelectedItem, ElementName=listbox1}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0">Vorname:</Label>
                <Label Grid.Row="1">Zuname:</Label>
                <Label Grid.Row="2">Alter:</Label>
                <Label Grid.Row="3">Stadt:</Label>
                <TextBox Name="txtFirstName" Grid.Row="0" Text="{Binding FirstName}" />
                <TextBox Name="txtLastName" Grid.Row="1" Text="{Binding LastName}" />
                <TextBox Name="txtAge" Grid.Row="2" Text="{Binding Age}" />
                <TextBox Name="txtCity" Grid.Row="3" Text="{Binding City}" />
            </Grid>
        </Grid>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Name="btnAdd" Click="btnAdd_Click">Hinzufügen</Button>
            <Button Name="btnDelete" Click="btnDelete_Click">Löschen</Button>
        </StackPanel>
    </Grid>
</Window>

