<Window x:Class="Flyad7_WPF.WdTest"
        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:Flyad7_WPF"
        xmlns:conv="clr-namespace:Flyad7_WPF.Converters"
        mc:Ignorable="d"
        Title="WdTest" Height="700" Width="735">
    <Window.Resources>
        <conv:BytesConverter x:Key="bytesconv"/>

        <Style TargetType="TextBlock" x:Key="Styles.Text.ItemTitle" BasedOn="{StaticResource Styles.Text.FieldHeader}">
            <Setter Property="Width" Value="60" />
        </Style>

        <Style TargetType="TextBlock" x:Key="Styles.Text.GridHeader">
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="TextWrapping" Value="WrapWithOverflow"/>
            <Setter Property="Margin" Value="5" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="FontSize" Value="15" />
        </Style>
        <Style TargetType="TextBlock"  x:Key="Styles.Text.GridTick" BasedOn="{StaticResource Styles.Text.FieldContent.Led}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="FontSize" Value="20" />
        </Style>

        <Style TargetType="Border" x:Key="Styles.Border.IO2">
            <Setter Property="Background" Value="Green"/>
            <Setter Property="Height" Value="12"/>
            <Setter Property="Width" Value="10"/>
            <Setter Property="Margin" Value="1,1"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag}" Value="True">
                    <Setter Property="Background" Value="Gray"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid ShowGridLines="True" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <ScrollViewer>
                <Grid ShowGridLines="True" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid ShowGridLines="True" Margin="{StaticResource ControlMargin}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="150"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="1.连接"/>
                        <TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsConnected_OK}" />
                        <StackPanel Grid.Row="0" Grid.Column="3" Margin="{StaticResource ControlMargin}">

                            <StackPanel Orientation="Horizontal" >
                                <TextBlock Style="{StaticResource Styles.Text.ItemTitle}" Text="硬件版本"/>
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding HardVersion}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.IsConnected}" Tag="{Binding IsConnected}"/>
                                <Button Style="{StaticResource Styles.Button.Square2}" Command="{Binding ReConnectCmd}" Content="重连" IsEnabled="{Binding IsEnableReConnect}"/>
                            </StackPanel>

                        </StackPanel>
                        <TextBlock Grid.Row="1" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="2.初始化＆设置8000小时使用码"/>
                        <TextBlock Grid.Row="1" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsInitArea_OK}" />
                        <StackPanel Grid.Row="1" Grid.Column="3" Margin="{StaticResource ControlMargin}">

                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.ItemTitle}" Text="序列码"/>
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Code, Converter={StaticResource bytesconv}}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.ItemTitle}" Text="授权码"/>
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Access, Converter={StaticResource bytesconv}}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.ItemTitle}" Text="使用时间"/>
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Hours}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{StaticResource Styles.Button.Square2}" Command="{Binding InitAreaCmd}" Content="初始化序列码，写入授权码"/>
                                <Button Style="{StaticResource Styles.Button.Square2}" Command="{Binding SetInitAreaOkCmd}" Content="成功"/>
                            </StackPanel>
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" Foreground="Red" TextAlignment="Left" TextWrapping="WrapWithOverflow" Text="{Binding InitAreaMessage}"/>
                        </StackPanel>


                        <TextBlock Grid.Row="2" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="3.输入亮灯"/>
                        <TextBlock Grid.Row="2" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsInput_OK}" />

                        <TextBlock Grid.Row="3" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="4.输出跑马灯"/>
                        <TextBlock Grid.Row="3" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsOutput_OK}" />

                        <StackPanel Grid.Row="2" Grid.Column="2" Grid.RowSpan="2" Margin="{StaticResource ControlMargin}">
                            <UniformGrid Columns="20" Margin="2,0" VerticalAlignment="Top" HorizontalAlignment="Left" >
                                <UniformGrid.Resources>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.IO}" />
                                </UniformGrid.Resources>
                                <TextBlock />
                                <TextBlock Text="0" />
                                <TextBlock Text="1" />
                                <TextBlock Text="2" />
                                <TextBlock Text="3" />
                                <Grid />
                                <TextBlock Text="4" />
                                <TextBlock Text="5" />
                                <TextBlock Text="6" />
                                <TextBlock Text="7" />
                                <Grid />
                                <TextBlock Text="8" />
                                <TextBlock Text="9" />
                                <TextBlock Text="10" />
                                <TextBlock Text="11" />
                                <Grid />
                                <TextBlock Text="12" />
                                <TextBlock Text="13" />
                                <TextBlock Text="14" />
                                <TextBlock Text="15" />
                                <TextBlock FontWeight="Bold" Text="X" />
                                <Border Tag="{Binding IStatus, ConverterParameter=0, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=1, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=2, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=3, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Grid />
                                <Border Tag="{Binding IStatus, ConverterParameter=4, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=5, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=6, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=7, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Grid />
                                <Border Tag="{Binding IStatus, ConverterParameter=8, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=9, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=10, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=11, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Grid />
                                <Border Tag="{Binding IStatus, ConverterParameter=12, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=13, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=14, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding IStatus, ConverterParameter=15, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />

                                <TextBlock FontWeight="Bold" Text="ok" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=0, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=1, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=2, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=3, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Grid />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=4, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=5, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=6, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=7, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Grid />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=8, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=9, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=10, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=11, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Grid />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=12, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=13, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=14, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />
                                <Border Tag="{Binding IStatusOk, ConverterParameter=15, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO2}" />



                                <TextBlock FontWeight="Bold" Text="Y" />
                                <Border Tag="{Binding OStatus, ConverterParameter=0, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=1, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=2, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=3, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Grid />
                                <Border Tag="{Binding OStatus, ConverterParameter=4, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=5, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=6, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Border Tag="{Binding OStatus, ConverterParameter=7, Converter={StaticResource io2bconv}}"
                                                    Style="{StaticResource Styles.Border.IO}" />
                                <Grid />
                            </UniformGrid>
                            <StackPanel Orientation="Horizontal">
                                <Button Style="{StaticResource Styles.Button.Square2}" Command="{Binding SetOutputOKCmd}" Content="输出正常"/>
                            </StackPanel>
                        </StackPanel>

                        <TextBlock Grid.Row="4" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="5.编码器2变化"/>
                        <TextBlock Grid.Row="4" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsEncoder2_OK}" />
                        <StackPanel Grid.Row="4" Grid.Column="2" >
                            <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="编码器2"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}">
                                                    <Run  Text="{Binding Position2,Mode=OneWay}"/>p
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                        <TextBlock Grid.Row="5" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="6.电机正反转，编码器1变化"/>
                        <TextBlock Grid.Row="5" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsEncoder1_OK}" />
                        <StackPanel Grid.Row="5" Grid.Column="2" >
                            <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="编码器1"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}">
                                                    <Run  Text="{Binding Position,Mode=OneWay}"/>p
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>
                        <TextBlock Grid.Row="6" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}">
                    7.插电阻9.8K<LineBreak/>拧电位器 AD=13500±500
                        </TextBlock>
                        <TextBlock Grid.Row="6" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsAdK_OK}" />
                        <StackPanel Grid.Row="6" Grid.Column="2" >
                            <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="AD值"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}">
                                                    <Run  Text="{Binding AD,Mode=OneWay}"/>
                                </TextBlock>
                            </StackPanel>
                        </StackPanel>


                        <TextBlock Grid.Row="7" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}">
                            8.输入三角波<LineBreak/>
                            频率0.01Hz<LineBreak/>
                            幅度1.3V<LineBreak/>
                            偏移0.5V<LineBreak/>
                            检查AD值 [1000~62999]
                        </TextBlock>
                        <TextBlock Grid.Row="7" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsAd_OK}" />
                        <StackPanel Grid.Row="7" Grid.Column="2" >
                            <StackPanel >
                                <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="已经出现过不同AD值数量="/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent}">
                                    <Run  Text="{Binding AdNumberSuccessCount,Mode=OneWay}"/>/<Run Text="{Binding AdNumberCount,Mode=OneWay}"/>
                                    </TextBlock>
                                </StackPanel>
                                <Expander Header="各分组情况" IsExpanded="False">
                                    <DataGrid Grid.Row="1" ItemsSource="{Binding AdNumberArrays}" AutoGenerateColumns="False" IsReadOnly="True" Margin="{StaticResource ControlMargin}"
                                      AlternationCount ="5"
                                      RowHeaderWidth="0"
                                      >
                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="开始" Binding="{Binding StartNumber}" />
                                            <DataGridTextColumn Header="总数" Binding="{Binding NumberCount}" />
                                            <DataGridTextColumn Header="出现数" Binding="{Binding SuccessCount}" />
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Expander>

                            </StackPanel>
                        </StackPanel>
                        <TextBlock Grid.Row="8" Grid.Column="1" Style="{StaticResource Styles.Text.GridHeader}" Text="全部测试完成"/>
                        <TextBlock Grid.Row="8" Grid.Column="0" Style="{StaticResource Styles.Text.GridTick}" Tag="{Binding IsAll_OK}" />
                    </Grid>
                </Grid>
            </ScrollViewer>

            <Grid Grid.Column="1" Margin="{StaticResource ControlMargin}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="通过数"/>
                        <TextBlock Style="{StaticResource Styles.Text.FieldContent}" FontSize="20" Foreground="White" Background="Green" Text="{Binding SuccessCnt,Mode=OneWay}"/>
                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="个"/>
                        <Button Style="{StaticResource Styles.Button.Square2}" Command="{Binding ClearFlyAdStatesCmd}" Content="清空" />
                    </StackPanel>
                </StackPanel>
                <ListBox Grid.Row="1" ItemsSource="{Binding Codes}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding .}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>

        </Grid>
    </Grid>
</Window>
