<Window x:Class="RFIDReaderTC.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:RFIDReaderTC"  
        xmlns:local_index="clr-namespace:RFIDReaderTC.Commons"  
        xmlns:viewmodel="clr-namespace:RFIDReaderTC.ViewModel"
        xmlns:hc="https://handyorg.github.io/handycontrol"
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
        mc:Ignorable="d"
        Title="智能库房采集系统" Height="850" Width="1200">
    <!--<Window.DataContext>
        <viewmodel:MainWindowViewModel></viewmodel:MainWindowViewModel>
    </Window.DataContext>-->
    <Window.Resources>
        <Style TargetType="Thumb" x:Key="CustomThumbStyle">
            <!-- 设置Thumb的背景 -->
            <Setter Property="Background" Value="Transparent"/>
            <!-- 设置Thumb的边框 -->
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <!-- 设置Thumb的宽度 -->
            <Setter Property="Height" Value="20"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Bottom"/>
            <Setter Property="Cursor" Value="SizeNS"/>

            <!-- 自定义控件模板 -->
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Thumb">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <!-- 这里可以定义Thumb的内容 -->
                                <Rectangle Fill="Transparent" />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <local_index:IndexConverter x:Key="IndexToSerialNumberConverter" />
        <local_index:RunTextConverter x:Key="RunTextConverter" />
        <local_index:ReadRunTextConverter x:Key="ReadRunTextConverter" />
        <local_index:EllipseFillConverter x:Key="EllipseFillConverter" />
        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    </Window.Resources>

    <Grid Background="#EFF1F3">
        <Grid.RowDefinitions>
            <RowDefinition Height="68"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="15"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Background="White">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"></ColumnDefinition>
                <ColumnDefinition Width="1*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="1" Source="/Resources/Image/title.png" VerticalAlignment="Center" HorizontalAlignment="Right"></Image>
            <WrapPanel Grid.Column="0" VerticalAlignment="Center" Margin="50,0,0,0">
                <Image Source="/Resources/Image/kufanghuanjing.png" Height="25" Margin="0,0,15,0"></Image>
                <Image Source="/Resources/Image/name.png" Height="20"></Image>
            </WrapPanel>

        </Grid>

        <Grid Name="MenuView" Panel.ZIndex="1" Visibility="{Binding MenuView, Converter={StaticResource BoolToVisibilityConverter}}" Grid.Row="1" Grid.Column="2" >
            <Border  Background="White" CornerRadius="10" Margin="20,10">
                <Grid Margin="30,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"></RowDefinition>
                        <RowDefinition Height="70"></RowDefinition>
                    </Grid.RowDefinitions>

                    <StackPanel Margin="40" Grid.Row="0">
                        <TextBlock FontSize="20" FontWeight="Bold" Foreground="#666">基 础 配 置</TextBlock>
                        <StackPanel Margin="10,20">
                            <Grid Margin="0,0,0,15">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" Grid.Column="0">工控平台地址:</TextBlock>
                                <TextBox VerticalAlignment="Center" Width="300" HorizontalAlignment="Left" Grid.Column="1" Text="{Binding UploadPath}"></TextBox>
                            </Grid>
                            <Grid Margin="0,0,0,15">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" Grid.Column="0">调度服务地址:</TextBlock>
                                <TextBox VerticalAlignment="Center" Width="300" HorizontalAlignment="Left" Grid.Column="1" Text="{Binding DispatchPath}"></TextBox>
                            </Grid>
                            <Grid Margin="0,0,0,15">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" Grid.Column="0">读写器IP:</TextBlock>
                                <TextBox VerticalAlignment="Center" Width="300" HorizontalAlignment="Left" Grid.Column="1" Text="{Binding ReadUrl}"></TextBox>
                            </Grid>
                            <Grid Margin="0,0,0,15">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="150"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" Grid.Column="0">LED IP:</TextBlock>
                                <TextBox VerticalAlignment="Center" Width="300" HorizontalAlignment="Left" Grid.Column="1" Text="{Binding LEDPath}"></TextBox>
                            </Grid>
                        </StackPanel>
                        <TextBlock FontSize="20" FontWeight="Bold" Foreground="#666">读 写 器 配 置</TextBlock>
                        <Grid Margin="10,20">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"></ColumnDefinition>
                                <ColumnDefinition Width="1*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0">
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="150"></ColumnDefinition>
                                        <ColumnDefinition Width="1*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock VerticalAlignment="Center" Grid.Column="0">天线1读取功率:</TextBlock>
                                    <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna1}"  HorizontalAlignment="Left" Grid.Column="1">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewTextInput">
                                                <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </TextBox>
                                </Grid>
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="150"></ColumnDefinition>
                                        <ColumnDefinition Width="1*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock VerticalAlignment="Center" Grid.Column="0">天线2读取功率:</TextBlock>
                                    <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna2}"   HorizontalAlignment="Left" Grid.Column="1">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewTextInput">
                                                <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </TextBox>
                                </Grid>
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="150"></ColumnDefinition>
                                        <ColumnDefinition Width="1*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock VerticalAlignment="Center" Grid.Column="0">天线3读取功率:</TextBlock>
                                    <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna3}"   HorizontalAlignment="Left" Grid.Column="1">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewTextInput">
                                                <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </TextBox>
                                </Grid>
                                <Grid Margin="0,0,0,15">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="150"></ColumnDefinition>
                                        <ColumnDefinition Width="1*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock VerticalAlignment="Center" Grid.Column="0">天线4读取功率:</TextBlock>
                                    <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna4}"   HorizontalAlignment="Left" Grid.Column="1">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="PreviewTextInput">
                                                <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </TextBox>
                                </Grid>
                            </StackPanel>
                            <ScrollViewer Grid.Column="1" HorizontalAlignment="Left">
                                <StackPanel>
                                    <Grid Margin="0,0,0,15">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="150"></ColumnDefinition>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock VerticalAlignment="Center" Grid.Column="0">天线5读取功率:</TextBlock>
                                        <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna5}"   HorizontalAlignment="Left" Grid.Column="1">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="PreviewTextInput">
                                                    <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </TextBox>
                                    </Grid>
                                    <Grid Margin="0,0,0,15">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="150"></ColumnDefinition>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock VerticalAlignment="Center" Grid.Column="0">天线6读取功率:</TextBlock>
                                        <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna6}"   HorizontalAlignment="Left" Grid.Column="1">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="PreviewTextInput">
                                                    <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </TextBox>
                                    </Grid>
                                    <Grid Margin="0,0,0,15">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="150"></ColumnDefinition>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock VerticalAlignment="Center" Grid.Column="0">天线7读取功率:</TextBlock>
                                        <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna7}"   HorizontalAlignment="Left" Grid.Column="1">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="PreviewTextInput">
                                                    <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </TextBox>
                                    </Grid>
                                    <Grid Margin="0,0,0,15">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="150"></ColumnDefinition>
                                            <ColumnDefinition Width="1*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock VerticalAlignment="Center" Grid.Column="0">天线8读取功率:</TextBlock>
                                        <TextBox  VerticalAlignment="Center" InputMethod.IsInputMethodEnabled="False" Width="100" Text="{Binding Antenna8}"   HorizontalAlignment="Left" Grid.Column="1">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="PreviewTextInput">
                                                    <i:CallMethodAction TargetObject="{Binding}" MethodName="TextBox_PreviewTextInput"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </TextBox>
                                    </Grid>
                                </StackPanel>
                            </ScrollViewer>
                        </Grid>
                    </StackPanel>
                    <Grid Grid.Row="1" >
                        <Button HorizontalAlignment="Right" Width="110" Content="保存配置并重启"  Command="{Binding ButtonSaveCommand}" Height="40" Margin="30,0,180,0" VerticalAlignment="Center">
                            <Button.Resources>
                                <Style TargetType="Button">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type Button}">
                                                <Border BorderThickness="1" BorderBrush="#2048EC" CornerRadius="5" Background="Transparent">
                                                    <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Cursor" Value="Hand"/>
                                    <Setter Property="Foreground" Value="#2048EC"/>
                                    <Setter Property="Visibility" Value="Visible"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Issensor}" Value="True">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Resources>
                        </Button>
                        <Button HorizontalAlignment="Right" Width="120" Style="{StaticResource BtnCornerRadius2}"  Command="{Binding ButtonMenuViewCommand}"  Content="退出" Height="40" Margin="30,0" VerticalAlignment="Center"></Button>
                    </Grid>
                </Grid>
            </Border>
        </Grid>
        
        <Grid Name="HomeView" Grid.Row="1" Grid.Column="2">
            <Grid Margin="20,20,20,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="20"></RowDefinition>
                    <RowDefinition Height="150"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Grid.RowSpan="3" Margin="0,0,0,10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="7*"></ColumnDefinition>
                        <ColumnDefinition Width="20"></ColumnDefinition>
                        <ColumnDefinition Width="3*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0"  Name="MainGrid">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="2*"/>
                            <RowDefinition Height="10"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="4*"/>
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" Background="White" Margin="0,0,0,1" CornerRadius="10,10,0,0">
                            <Grid Margin="20,0">
                                <TextBlock Grid.Row="0" VerticalAlignment="Center" FontSize="16" Foreground="#000000">箱条码</TextBlock>
                                <WrapPanel VerticalAlignment="Center" HorizontalAlignment='Right'>
                                    <Image Source="/Resources/Image/icon1.png" Height="15" Margin="0,0,10,0"></Image>
                                    <TextBlock x:Name="lbTagsCount" Grid.Row="0" FontSize="16" Foreground="#00BD62" Text="{Binding LbTagsCount,Mode=OneWay}"></TextBlock>
                                </WrapPanel>
                            </Grid>
                        </Border>
                        <Border Grid.Row="1" CornerRadius="0,0,10,10">
                            <ListView ItemsSource="{Binding TagInfos}" Background="White" BorderBrush="Transparent" BorderThickness="0" AlternationCount="1">
                                <ListView.View>
                                    <GridView>
                                        <!-- 序号列 -->
                                        <GridViewColumn Width="80" Header="序号" DisplayMemberBinding ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource IndexToSerialNumberConverter}}" />
                                        <GridViewColumn Width="400" Header="资产条码" DisplayMemberBinding="{Binding Tag,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                        <GridViewColumn Width="200" Header="采集次数" DisplayMemberBinding="{Binding Count,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </Border>
                        <!-- 拖动区域 -->
                        <Thumb Grid.Row="2" Height="20" Style="{StaticResource CustomThumbStyle}" DragDelta="Thumb_DragDelta"  VerticalAlignment="Center"  Cursor="SizeNS"/>
                        <Border Grid.Row="3" Background="White" Margin="0,0,0,1" CornerRadius="10,10,0,0">
                            <Grid Margin="20,0">
                                <TextBlock Grid.Row="0" VerticalAlignment="Center" FontSize="16" Foreground="#000000">表条码</TextBlock>
                                <WrapPanel VerticalAlignment="Center" HorizontalAlignment='Right'>
                                    <Image Source="/Resources/Image/icon1.png" Height="15" Margin="0,0,10,0"></Image>
                                    <TextBlock x:Name="BoxCount" Grid.Row="0" FontSize="16" Foreground="#00BD62" Text="{Binding LbGoodsTagsCount,Mode=OneWay}"></TextBlock>
                                </WrapPanel>
                            </Grid>
                        </Border>
                        <Border Grid.Row="4" Background="White" CornerRadius="0,0,10,10">
                            <ListView ItemsSource="{Binding GoodsTagInfos}" Background="White" BorderBrush="Transparent" BorderThickness="0">
                                <ListView.View>
                                    <GridView>
                                        <!-- 序号列 -->
                                        <GridViewColumn Width="80" Header="序号" DisplayMemberBinding ="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource IndexToSerialNumberConverter}}" />
                                        <GridViewColumn Width="400" Header="资产条码" DisplayMemberBinding="{Binding Tag,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                        <GridViewColumn Width="200" Header="采集次数" DisplayMemberBinding="{Binding Count,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </Border>
                    </Grid>
                    
                    <Grid Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="6*"></RowDefinition>
                            <RowDefinition Height="2.2*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <RichTextBox Grid.Row="0" Name="Mesg" ScrollViewer.VerticalScrollBarVisibility="Auto"> 

                        </RichTextBox>
                        <!--<WrapPanel Grid.Row="1">
                            <Button Width="100" Height="30" Command="{Binding ButtonConnectCommand}">连接</Button>
                        </WrapPanel>-->
                        <Grid Grid.Row="1">
                            <Grid VerticalAlignment="Top">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                    <ColumnDefinition Width="20"></ColumnDefinition>
                                    <ColumnDefinition Width="1*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <Button Grid.Column="0" Height="70" Style="{StaticResource BtnCornerRadius_2}" Command="{Binding ButtonReadOpenCommand}" Margin="0,10" Content="开 始 读 取" IsEnabled="{Binding ReaderPerson}"></Button>
                                <Button Grid.Column="2" Height="70" Style="{StaticResource BtnCornerRadius_1}" Command="{Binding ButtonReadCloseCommand}" Margin="0,10" Content="停 止 读 取" IsEnabled="{Binding ReaderPerson}"></Button>
                            </Grid>
                            <StackPanel VerticalAlignment="Bottom">
                                <Button Height="70" Style="{StaticResource BtnCornerRadius_1}" Command="{Binding ButtonMenuViewCommand}" Margin="0,10" Content="功 能 设 置" Click="Button_Click"></Button>
                                <!--<Button Width="100" Height="30" Command="{Binding ButtonAddCommand}">增加数据</Button>-->
                            </StackPanel>
                        </Grid>
                    </Grid>
                </Grid>
            </Grid>
        </Grid>
        <Border Grid.Row="2" Margin="20,5,20,5" Background="White" CornerRadius="10">
            <WrapPanel VerticalAlignment="Center" Margin="20,0">
                <WrapPanel>
                    <Ellipse Width="20" Height="20" Fill="{Binding DispatchState, Converter={StaticResource EllipseFillConverter}}" />
                    <TextBlock Margin="10,0,0,0" VerticalAlignment="Center">
                        调度服务连接状态：
                        <Run Foreground="{Binding DispatchState, Converter={StaticResource EllipseFillConverter}}" Text="{Binding DispatchState, Converter={StaticResource RunTextConverter}}"/>
                    </TextBlock>
                </WrapPanel>
                <WrapPanel Margin="50,0">
                    <Ellipse Width="20" Height="20" Fill="{Binding ReaderState, Converter={StaticResource EllipseFillConverter}}" />
                    <TextBlock Margin="10,0,0,0" VerticalAlignment="Center">
                         读写器连接状态：
                         <Run Foreground="{Binding ReaderState, Converter={StaticResource EllipseFillConverter}}" Text="{Binding ReaderState, Converter={StaticResource RunTextConverter}}"/>
                    </TextBlock>
                </WrapPanel>
                <WrapPanel>
                    <Ellipse Width="20" Height="20" Fill="Green" />
                    <TextBlock Margin="10,0,0,0" VerticalAlignment="Center">
                      读写器工作状态：
                      <Run Foreground="Green" Text="{Binding ReadIsOpen, Converter={StaticResource ReadRunTextConverter}}"/>
                                </TextBlock>
                </WrapPanel>
            </WrapPanel>
        </Border>
    </Grid>
</Window>
