<Window x:Class="Intelligent_HumanNumberStatistic.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:winform="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="HumanNumberStatistic(人数统计)" Height="580" Width="1285" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <Style x:Key="NormalButtonStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Width" Value="120" />
            <Setter Property="Height" Value="30" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ButtonBase}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.2"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="border" BorderThickness="2" Opacity="1" CornerRadius="4" BorderBrush="#FF6BAFDE">
                                <Border.Background>
                                    <LinearGradientBrush>
                                        <GradientStop Color="#69B1ACDE" Offset="0"/>
                                        <GradientStop />
                                        <GradientStop Color="#33C2BEBE" Offset="0.297"/>
                                        <GradientStop Offset="1" Color="#00FFFF50" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Label x:Name="lable" Content="{TemplateBinding Content}" HorizontalAlignment="Center"  VerticalAlignment="Center" Padding="0" Foreground="Black" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True"/>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" TargetName="lable" Value="Gray" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="True">
                                <Setter Property="Foreground" TargetName="lable" Value="Black" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
        <SolidColorBrush x:Key="PopupBackground" Color="#ffffff" />
        <SolidColorBrush x:Key="InputBackground" Color="#ffffff" />
        <SolidColorBrush x:Key="InputBackgroundHover" Color="#ffffff" />
        <SolidColorBrush x:Key="InputBorder" Color="#cccccc" />
        <SolidColorBrush x:Key="InputBorderHover" Color="#cccccc" />
        <SolidColorBrush x:Key="InputText" Color="#333333" />
        <SolidColorBrush x:Key="InputTextHover" Color="#333333" />
        <SolidColorBrush x:Key="InputTextDisabled" Color="#919191" />

        <Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="MinWidth" Value="0"/>
            <Setter Property="MinHeight" Value="0"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
            <Grid Name="MainGrid" SnapsToDevicePixels="true">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                </Grid.ColumnDefinitions>
                <Popup Name="PART_Popup"
                   AllowsTransparency="true"
                   Grid.ColumnSpan="2"
                   Placement="Bottom"
                   Margin="1"
                   IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                    <Grid Margin="4" MinWidth="{Binding ElementName=MainGrid,Path=ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                        <Border Background="#0C000000" BorderBrush="#0F000000" BorderThickness="1" CornerRadius="2.5" Margin="-1" />
                        <Border Background="#0A000000" BorderBrush="#0C000000" BorderThickness="1" CornerRadius="2.75" Margin="-2" />

                        <Border x:Name="DropDownBorder" 
                            Background="{DynamicResource PopupBackground}"
                            BorderBrush="#FF6BAFDE"
                            BorderThickness="1"
                            Margin="0,-1,0,0">
                            <!-- popup border thickness not dependent on BorderThickness property-->
                            <ScrollViewer Name="DropDownScrollViewer">
                                <Grid RenderOptions.ClearTypeHint="Enabled">
                                    <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                        <Rectangle 
                                        Name="OpaqueRect"
                                        Height="{Binding ElementName=DropDownBorder,Path=ActualHeight}" 
                                        Width="{Binding ElementName=DropDownBorder,Path=ActualWidth}" 
                                        Fill="{Binding ElementName=DropDownBorder,Path=Background}" />
                                    </Canvas>
                                    <ItemsPresenter Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </Grid>
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </Popup>
                <ToggleButton Grid.ColumnSpan="2"
                          Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                          Padding="0,0,0,10"/>

                <Path Name="Arrow"
                  Grid.ColumnSpan="2"
                  Margin="3,1,8,0"
                  Fill="{TemplateBinding Foreground}"
                  Data="{DynamicResource DownArrowGeometry}"
                  HorizontalAlignment="Right"
                  VerticalAlignment="Center" IsHitTestVisible="False"/>
                <TextBox x:Name="PART_EditableTextBox"
                     HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                     IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
                     Margin="{TemplateBinding Padding}"
                     Padding="2,0,0,1"
                     Style="{StaticResource ComboBoxEditableTextBox}"
                     VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="HasItems" Value="false">
                    <Setter TargetName="DropDownBorder" Property="Height" Value="95"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="{DynamicResource InputTextDisabled}"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Background" Value="{DynamicResource InputBackgroundHover}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource InputBorderHover}" />
                </Trigger>
                <Trigger Property="IsFocused" Value="true">
                    <Setter Property="BorderBrush" Value="#FF6BAFDE" />
                </Trigger>
                <Trigger SourceName="PART_EditableTextBox" Property="IsFocused" Value="true">
                    <Setter Property="BorderBrush" Value="#FF6BAFDE" />
                </Trigger>
                <Trigger Property="IsGrouping" Value="true">
                    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                </Trigger>
                <Trigger SourceName="DropDownScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false" >
                    <Setter TargetName="OpaqueRect" 
                        Property="Canvas.Top" 
                        Value="{Binding ElementName=DropDownScrollViewer, Path=VerticalOffset}" />
                    <Setter TargetName="OpaqueRect" 
                        Property="Canvas.Left" 
                        Value="{Binding ElementName=DropDownScrollViewer, Path=HorizontalOffset}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        
        <Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
            <Setter Property="Foreground" Value="{DynamicResource InputText}"/>
            <Setter Property="Background" Value="{DynamicResource InputBackground}"/>
            <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="Padding" Value="7,3,8,3"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ComboBox}">
                        <Grid Name="MainGrid" SnapsToDevicePixels="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                            </Grid.ColumnDefinitions>
                            <Popup Name="PART_Popup"
                               AllowsTransparency="true"
                               Grid.ColumnSpan="2"
                               Placement="Bottom"
                               Margin="1"
                               IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                               PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                                <Grid Margin="4" MinWidth="{Binding ElementName=MainGrid,Path=ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border Background="#0C000000" BorderBrush="#0F000000" BorderThickness="1" CornerRadius="3" Margin="-1" />
                                    <Border Background="#0A000000" BorderBrush="#0C000000" BorderThickness="1" CornerRadius="3" Margin="-2" />

                                    <Border x:Name="DropDownBorder"
                                        Background="{DynamicResource PopupBackground}"
                                        BorderBrush="#FF6BAFDE"
                                        BorderThickness="1"
                                        Margin="0,-1,0,0">
                                        <!-- popup border thickness not dependent on BorderThickness property-->
                                        <ScrollViewer Name="DropDownScrollViewer">
                                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                                <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                                    <Rectangle 
                                                    Name="OpaqueRect"
                                                    Height="{Binding ElementName=DropDownBorder,Path=ActualHeight}" 
                                                    Width="{Binding ElementName=DropDownBorder,Path=ActualWidth}" 
                                                    Fill="{Binding ElementName=DropDownBorder,Path=Background}" />
                                                </Canvas>
                                                <ItemsPresenter Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                            </Grid>
                                        </ScrollViewer>
                                    </Border>
                                </Grid>
                            </Popup>
                            <ToggleButton Grid.ColumnSpan="2" 
                                      Background="{TemplateBinding Background}"
                                      BorderBrush="{TemplateBinding BorderBrush}"
                                      BorderThickness="{TemplateBinding BorderThickness}"
                                      IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                      Padding="0,0,0,10"/>

                            <Path Name="Arrow"
                              Grid.ColumnSpan="2"
                              Margin="3,1,8,0"
                              Fill="{TemplateBinding Foreground}"
                              Data="{DynamicResource DownArrowGeometry}"
                              HorizontalAlignment="Right"
                              VerticalAlignment="Center" IsHitTestVisible="False"/>

                            <ContentPresenter IsHitTestVisible="false"
                                          Margin="{TemplateBinding Padding}"
                                          Content="{TemplateBinding SelectionBoxItem}"
                                          ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                          ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="HasItems" Value="false">
                                <Setter TargetName="DropDownBorder" Property="Height" Value="95"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource InputTextDisabled}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="{DynamicResource InputBackgroundHover}" />
                                <Setter Property="BorderBrush" Value="{DynamicResource InputBorderHover}" />
                            </Trigger>
                            <Trigger Property="IsFocused" Value="true">
                                <Setter Property="BorderBrush" Value="#FF6BAFDE" />
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="true">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </Trigger>
                            <Trigger SourceName="DropDownScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false" >
                                <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Top" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=VerticalOffset}" />
                                <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Left" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=HorizontalOffset}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsEditable" Value="true">
                    <Setter Property="IsTabStop" Value="false"/>
                    <Setter Property="Padding" Value="3"/>
                    <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Margin="5,0">
            <GroupBox Header="Operate(操作)">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="IP(IP地址):" VerticalAlignment="Center"/>
                    <TextBox x:Name="tb_ip" Text="10.11.16.229" VerticalAlignment="Center" Margin="5,0,0,0" Width="100" Height="23"/>
                    <TextBlock Text="Port(端口):" VerticalAlignment="Center" Margin="5,0,0,0"/>
                    <TextBox x:Name="tb_port" Text="37777" VerticalAlignment="Center" Margin="5,0,0,0" Width="60" Height="23"/>
                    <TextBlock Text="Name(用户名):" VerticalAlignment="Center" Margin="5,0,0,0"/>
                    <TextBox x:Name="tb_name" Text="admin" VerticalAlignment="Center" Margin="5,0,0,0" Width="80" Height="23"/>
                    <TextBlock Text="Password(密码):" VerticalAlignment="Center" Margin="5,0,0,0"/>
                    <PasswordBox x:Name="tb_password" Password="admin123" VerticalAlignment="Center" Margin="5,0,0,0" Width="80" Height="23"/>
                    <Button x:Name="btn_login" Content="Login(登录)" Style="{StaticResource NormalButtonStyle}" Width="120" Height="25" Margin="10,0,0,0" Click="btn_login_Click"/>
                    <ComboBox x:Name="combox" Height="25" VerticalAlignment="Center" Width="60" Margin="10,0,0,0" IsReadOnly="True"/>
                    <Button x:Name="btn_realplay" Content="RealPlay(监视)" Style="{StaticResource NormalButtonStyle}" Width="140" Height="25" Margin="10,0,0,0" Click="btn_realplay_Click"/>
                    <Button x:Name="btn_attach" Content="Attach(订阅)" Style="{StaticResource NormalButtonStyle}" Width="120" Height="25" Margin="10,0,0,0" Click="btn_attach_Click"/>
                    <Button x:Name="btn_clear" Content="Clear(清空)" Style="{StaticResource NormalButtonStyle}" Width="110" Height="25" Margin="10,0,0,0" Click="btn_clear_Click"/>
                </StackPanel>
            </GroupBox>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="500" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0" Margin="5" Background="Gray">
                <WindowsFormsHost>
                    <winform:PictureBox x:Name="pic" />
                </WindowsFormsHost>
            </Grid>
            <Grid Grid.Column="1" Margin="0,5,5,5">
                <ListView x:Name="listview">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Channel(通道)" Width="100" DisplayMemberBinding="{Binding Channel}"/>
                            <GridViewColumn Header="OSDIn(OSD进)" Width="100" DisplayMemberBinding="{Binding OSDIn}"/>
                            <GridViewColumn Header="OSDOut(OSD出)" Width="100" DisplayMemberBinding="{Binding OSDOut}"/>
                            <GridViewColumn Header="TodayIn(今天进)" Width="100" DisplayMemberBinding="{Binding TodayIn}"/>
                            <GridViewColumn Header="TodayOut(今天出)" Width="110" DisplayMemberBinding="{Binding TodayOut}"/>
                            <GridViewColumn Header="TotalIn(总共进)" Width="100" DisplayMemberBinding="{Binding TotalIn}"/>
                            <GridViewColumn Header="TotalOut(总共出)" Width="110" DisplayMemberBinding="{Binding TotalOut}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </Grid>
    </Grid>
</Window>
