<Page x:Class="FLY.Thick.Base.UI.PgGrid"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
      xmlns:local="clr-namespace:FLY.Thick.Base.UI"
      xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
      mc:Ignorable="d" 
      d:DesignHeight="1000" d:DesignWidth="1024"
      Background="#E6E6E6"
	Title="PgGrid" >
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="PgGridStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:PgGridVmUt x:Key="viewModel" IsADMode="True"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid d:DataContext="{StaticResource viewModel}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Background="{StaticResource Background_Title}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" >
                <Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/>
                <TextBlock Style="{StaticResource TextBlockStyle_Title}" Text="控制器调试"/>
                <StackPanel VerticalAlignment="Center">
                    <TextBlock Text="Grid图" FontSize="30" VerticalAlignment="Center" Margin="{StaticResource ControlMargin}" Foreground="LightGray"/>
                    <StackPanel Orientation="Horizontal" >
                        <TextBlock Style="{StaticResource TextBlockStyle_FieldHeader}" Text="AD模式" Foreground="LightGray"/>
                        <ToggleButton Style="{StaticResource CheckStyle}" HorizontalAlignment="Left" IsChecked="{Binding IsADMode}" Width="30" Height="auto"  Foreground="White" Background="#02FFFFFF" />
                    </StackPanel>
                </StackPanel>
                
            </StackPanel>
            <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
        </Grid>

        <ScrollViewer CanContentScroll="False" PanningMode="Both" Grid.Row="1"  >
            <StackPanel Margin="5">
                <Border Style="{StaticResource CardBorderStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid >
                            <StackPanel Orientation="Horizontal" Visibility="{Binding IsCanDownload,Converter={StaticResource visbilityconv}}">
                                <StackPanel Orientation="Vertical" Margin="5">
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="目标位置" />
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource TextBoxStyle_FieldContent}"
                                                 Text="{Binding TargetPos}" />
                                        <StackPanel Orientation="Horizontal" >
                                            <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                            <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}">
                                                <Run Text="{Binding TargetMm,Mode=OneWay}"/><Run Text="mm"/>
                                            </TextBlock>
                                            
                                        </StackPanel>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <Button Content="运行至" Style="{DynamicResource AccentedSquareButtonStyle2}" Command="{Binding RunToCmd}"
                                        />
                                    <TextBlock Text="{Binding Msg}" Style="{StaticResource TextBlockStyle_FieldContent_mm}"/>
                                </StackPanel>

                            </StackPanel>
                        </Grid>

                        <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top">
                            <Button Content="删除" Style="{StaticResource SquareButtonStyle2}" Command="{Binding ClearCmd}" Background="{StaticResource ValidationSummaryColor3}"/>
                            <Button Content="保存" Style="{StaticResource SquareButtonStyle2}" Command="{Binding SaveCmd}"/>
                            
                        </StackPanel>
                    </Grid>
                </Border>

                <Border Style="{StaticResource CardBorderStyle}" >
                    <StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <ItemsControl ItemsSource="{Binding SeriesInfos}" Margin="5" x:Name="itemSelect">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Button Style="{StaticResource ButtonStyle_empty}" Command="{Binding DataContext.SelectCmd, ElementName=itemSelect}" CommandParameter="{Binding }">
                                            <Border x:Name="bd" Background="WhiteSmoke" BorderBrush="{Binding Fill}" BorderThickness="2" Margin="2" Height="35" Width="80" >
                                                <TextBlock x:Name="tb" Text="{Binding Header}" FontSize="24" Foreground="{Binding Fill}" FontWeight="Bold"  VerticalAlignment="Center" HorizontalAlignment="Center"  />
                                            </Border>
                                        </Button>
                                        <DataTemplate.Triggers>
                                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                <Setter TargetName="bd" Property="Background" Value="{Binding Fill}"/>
                                                <Setter TargetName="bd" Property="BorderBrush" Value="LightGray"/>
                                                <Setter TargetName="tb" Property="Foreground" Value="WhiteSmoke"/>
                                            </DataTrigger>
                                        </DataTemplate.Triggers>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                            <StackPanel Grid.Column="1" Orientation="Horizontal">
                                <Button Content="获取正向" Style="{StaticResource AccentedSquareButtonStyle2}" Command="{Binding GetFDataCmd}" />
                                <Button Content="获取反向" Style="{StaticResource SquareButtonStyle2}" Command="{Binding GetBDataCmd}"  />
                            </StackPanel>
                            
                        </Grid>
                        

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <lvc:CartesianChart x:Name="chart1" Grid.Row="1" Margin="5" Height="350" MouseMove="UIElement_OnMouseMove" MouseDown="UIElement_MouseDown" MouseUp="UIElement_MouseUp"
                                            DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}"
                                            Series="{Binding Series}"
                                            >
                                <lvc:CartesianChart.AxisX>
                                    <lvc:Axis FontSize="16" >
                                        <lvc:Axis.Separator>
                                            <lvc:Separator Stroke="LightGray"/>
                                        </lvc:Axis.Separator>
                                        <lvc:Axis.Sections>
                                            <lvc:AxisSection Style="{StaticResource AxisSectionStyle}" Value="{Binding SectionValue}" SectionWidth="{Binding SectionWidth}" />
                                        </lvc:Axis.Sections>
                                    </lvc:Axis>
                                </lvc:CartesianChart.AxisX>
                                <lvc:CartesianChart.AxisY>
                                    <lvc:Axis FontSize="16" >
                                        <lvc:Axis.Separator>
                                            <lvc:Separator Stroke="LightGray"/>
                                        </lvc:Axis.Separator>
                                    </lvc:Axis>
                                </lvc:CartesianChart.AxisY>
                            </lvc:CartesianChart>
                            <Controls:RangeSlider Grid.Row="1" Grid.Column="1"
                                                  Margin="0,10"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="MouseHover"
                                                  AutoToolTipPlacement="TopLeft"
                                                  Orientation="Vertical"
                                                  LargeChange="10"
                                                  SmallChange="1"
                                                  Maximum="{Binding YMax}"
                                                  Minimum="{Binding YMin}"
                                                  
                                                  LowerValue="{Binding YLower}"
                                                  UpperValue="{Binding YUpper}" />
                            <Controls:RangeSlider 
                                                  Margin="10,0"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="MouseHover"
                                                  AutoToolTipPlacement="TopLeft"
                                                  LargeChange="10"
                                                  Maximum="{Binding XMax}"
                                                  Minimum="{Binding XMin}"
                                                  Orientation="Horizontal"
                                                  SmallChange="1"
                                                  LowerValue="{Binding XLower}"
                                                  UpperValue="{Binding XUpper}" />
                        </Grid>
                        
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource CardBorderStyle}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" >
                            <StackPanel Margin="5">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="测量位置" />
                                <StackPanel Orientation="Horizontal" >
                                    <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource TextBoxStyle_FieldContent}"
                                                 Text="{Binding MeasureValuePos}" />
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}">
                                                <Run Text="{Binding MeasureValueMm,Mode=OneWay}"/><Run Text="mm"/>
                                        </TextBlock>

                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="5">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="测量宽度" />
                                <StackPanel Orientation="Horizontal" >
                                    <TextBox HorizontalAlignment="Left" MaxWidth="150" Style="{StaticResource TextBoxStyle_FieldContent}"
                                                 Text="{Binding MeasureWidthPos}" />
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}">
                                                <Run Text="{Binding MeasureWidthMm,Mode=OneWay}"/><Run Text="mm"/>
                                        </TextBlock>

                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                            <Button Content="测量" Style="{DynamicResource AccentedSquareButtonStyle2}" Command="{Binding MeasureCmd}"/>

                            

                        </StackPanel>
                        <ItemsControl ItemsSource="{Binding SeriesInfos}" Grid.Column="1" Margin="5">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border x:Name="bd" Background="WhiteSmoke" BorderBrush="{Binding Fill}" BorderThickness="2" Margin="2" Height="35" Width="80" >
                                        <Viewbox>
                                            <TextBlock x:Name="tb" Text="{Binding Avg,StringFormat={}{0:F1}}" FontSize="24" Foreground="{Binding Fill}" FontWeight="Bold"  VerticalAlignment="Center" HorizontalAlignment="Center"  />
                                        </Viewbox>
                                    </Border>
                                    <DataTemplate.Triggers>
                                        <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                            <Setter TargetName="bd" Property="Background" Value="{Binding Fill}"/>
                                            <Setter TargetName="bd" Property="BorderBrush" Value="LightGray"/>
                                            <Setter TargetName="tb" Property="Foreground" Value="WhiteSmoke"/>
                                        </DataTrigger>
                                    </DataTemplate.Triggers>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Grid>
                </Border>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>