<Window
    x:Class="Tcp.Test2.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:local="clr-namespace:Tcp.Test2"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="300" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border Grid.Row="0">
            <ListBox ItemsSource="{Binding ListMessage}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border
                            Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ListBox}}"
                            Margin="0,0,-50,0"
                            TextBlock.Foreground="Blue">
                            <Grid Name="GridMessage" Margin="0,0,50,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <TextBlock
                                    x:Name="TxtTime"
                                    Grid.Row="0"
                                    Text="{Binding CreateTime, StringFormat='yyyy-MM-dd HH:mm:ss'}" />
                                <TextBlock
                                    Name="TxtMessage"
                                    Grid.Row="1"
                                    Text="{Binding Message}" />
                            </Grid>
                        </Border>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding IsAck}" Value="true">
                                <Setter TargetName="TxtTime" Property="Foreground" Value="red" />
                                <Setter TargetName="TxtMessage" Property="Foreground" Value="red" />
                                <Setter TargetName="TxtTime" Property="HorizontalAlignment" Value="Right" />
                                <Setter TargetName="TxtMessage" Property="HorizontalAlignment" Value="Right" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Border>
        <GridSplitter
            Grid.Row="1"
            Height="5"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Center"
            ResizeDirection="Rows" />
        <Border Grid.Row="2">
            <TextBox
                AcceptsReturn="True"
                Text="{Binding CurrentInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                TextWrapping="Wrap" />
        </Border>
        <Border Grid.Row="3">
            <Grid>
                <TextBlock VerticalAlignment="Center" Text="{Binding StatusMessage}" />
                <Button
                    Width="200"
                    Height="30"
                    Margin="5"
                    HorizontalAlignment="Right"
                    Command="{Binding SendCommand}"
                    Content="发送" />
            </Grid>
        </Border>
    </Grid>
</Window>
