<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" 
      xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" 
      mc:Ignorable="d" 
      d:DesignWidth="1024"
	Title="PgGrid" >
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Converter/Converters.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Themes/GraphStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:PgGridVmUt x:Key="viewModel" IsADMode="True"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid x:Name="grid_viewModel" d:DataContext="{StaticResource viewModel}"  Background="{StaticResource Brushes.Card.Background}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Background="{StaticResource Brushes.TitleBar.Background}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" >
                <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"  >
                    <iconPacks:PackIconMaterial Kind="ArrowLeftThick" />
                </Button>
                <TextBlock Style="{StaticResource Styles.TitleBar.Text}" Text="{StaticResource str.PgGrid.Title}"/>
                <StackPanel VerticalAlignment="Center">

                </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="{StaticResource ControlMargin}">
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}" Text="{StaticResource str.PgGrid.ScanChart}"/>
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Grid Margin="{StaticResource ControlMargin}">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition Height="auto"/>
                                </Grid.RowDefinitions>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition Height="auto"/>
                                    </Grid.RowDefinitions>
                                    <Grid>
                                        <lvc:CartesianChart x:Name="chart" Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" Series="{Binding Series}" MinHeight="250">
                                            <lvc:CartesianChart.AxisX>
                                                <lvc:Axis LabelFormatter="{Binding XFormatter}" 
                                      Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
                                      MaxValue="{Binding ZoomInHelper.XRangeSlider.Max}" MinValue="{Binding ZoomInHelper.XRangeSlider.Min}"
                                      >
                                                    <lvc:Axis.Separator>
                                                        <lvc:Separator Stroke="{StaticResource MahApps.Brushes.Gray2}" StrokeDashArray="3"  />

                                                    </lvc:Axis.Separator>
                                                    <lvc:Axis.Sections>
                                                        <!--图表缩放.选择器.X轴-->
                                                        <lvc:AxisSection Style="{StaticResource Styles.Axis.Section.Selected.ZoomIn}"
                                                                 Value="{Binding ZoomInHelper.SelectedXBegin}" />
                                                        <lvc:AxisSection Style="{StaticResource Styles.Axis.Section.Selected.ZoomIn}"
                                                                 Value="{Binding ZoomInHelper.SelectedXEnd}" />
                                                    </lvc:Axis.Sections>
                                                </lvc:Axis>
                                            </lvc:CartesianChart.AxisX>
                                            <lvc:CartesianChart.AxisY>
                                                <lvc:Axis LabelFormatter="{Binding YFormatter}" MaxValue="{Binding ZoomInHelper.YRangeSlider.Max}" MinValue="{Binding ZoomInHelper.YRangeSlider.Min}"
                                      Foreground="{StaticResource MahApps.Brushes.ThemeForeground}" FontFamily="Courier New">
                                                    <lvc:Axis.Separator>
                                                        <lvc:Separator Stroke="{StaticResource MahApps.Brushes.Gray2}" StrokeDashArray="3"  />
                                                    </lvc:Axis.Separator>
                                                    <lvc:Axis.Sections>
                                                        <!--图表缩放.选择器.Y轴-->
                                                        <lvc:AxisSection Style="{StaticResource Styles.Axis.Section.Selected.ZoomIn}"
                                                                 Value="{Binding ZoomInHelper.SelectedYBegin}"/>
                                                        <lvc:AxisSection Style="{StaticResource Styles.Axis.Section.Selected.ZoomIn}"
                                                                 Value="{Binding ZoomInHelper.SelectedYEnd}" />
                                                    </lvc:Axis.Sections>
                                                </lvc:Axis>
                                            </lvc:CartesianChart.AxisY>
                                        </lvc:CartesianChart>
                                        <StackPanel HorizontalAlignment="Right">
                                            <ItemsControl ItemsSource="{Binding SeriesInfos}" Margin="{StaticResource ControlMargin}" >
                                                <ItemsControl.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <StackPanel />
                                                    </ItemsPanelTemplate>
                                                </ItemsControl.ItemsPanel>
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Button Style="{StaticResource Styles.Button.Empty}" Command="{Binding DataContext.SelectCmd,ElementName=grid_viewModel}" CommandParameter="{Binding .}">
                                                            <StackPanel Orientation="Horizontal" >
                                                                <StackPanel.Style>
                                                                    <Style TargetType="StackPanel">
                                                                        <Style.Triggers>
                                                                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                                                <Setter Property="Background" Value="{StaticResource MahApps.Brushes.Gray.SemiTransparent}"/>
                                                                            </DataTrigger>
                                                                        </Style.Triggers>
                                                                    </Style>
                                                                </StackPanel.Style>
                                                                <Border Background="{Binding Fill}" Height="2" Width="30" Margin="{StaticResource ControlMargin}"/>
                                                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Foreground="{Binding Fill}" Text="{Binding Header}"/>
                                                            </StackPanel>
                                                        </Button>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </StackPanel>
                                    </Grid>
                                    <!--图表缩放.拖动条.X轴-->
                                    <Controls:RangeSlider Grid.Row="1"
                                                  Style="{StaticResource MahApps.Styles.RangeSlider}" 
                                                  Margin="{StaticResource ControlMargin}"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="None"
                                                  AutoToolTipPlacement="TopLeft"
                                                  Orientation="Horizontal"
                                                  LargeChange="10"
                                                  SmallChange="1"
                                                  Maximum="{Binding ZoomInHelper.XRangeSlider.SliderMax}"
                                                  Minimum="{Binding ZoomInHelper.XRangeSlider.SliderMin}"
                                                  LowerValue="{Binding ZoomInHelper.XRangeSlider.SliderLowerValue}"
                                                  UpperValue="{Binding ZoomInHelper.XRangeSlider.SliderUpperValue}" />
                                    <!--图表缩放.拖动条.Y轴-->
                                    <Controls:RangeSlider Grid.Column="1"
                                                  Style="{StaticResource MahApps.Styles.RangeSlider}" 
                                                  Margin="{StaticResource ControlMargin}"
                                                  Controls:SliderHelper.ChangeValueBy="LargeChange"
                                                  Controls:SliderHelper.EnableMouseWheel="None"
                                                  AutoToolTipPlacement="TopLeft"
                                                  Orientation="Vertical"
                                                  LargeChange="10"
                                                  SmallChange="1"
                                                  Maximum="{Binding ZoomInHelper.YRangeSlider.SliderMax}"
                                                  Minimum="{Binding ZoomInHelper.YRangeSlider.SliderMin}"
                                                  LowerValue="{Binding ZoomInHelper.YRangeSlider.SliderLowerValue}"
                                                  UpperValue="{Binding ZoomInHelper.YRangeSlider.SliderUpperValue}" />
                                    <!--图表缩放.按钮.全屏-->
                                    <Button Style="{StaticResource Styles.Button.Icon.Small}" 
                                    Grid.Row="1" Grid.Column="1"
                                    Command="{Binding ZoomInHelper.FullscreenCmd}">
                                        <iconPacks:PackIconMaterial Kind="Fullscreen"  Width="22"/>
                                    </Button>
                                </Grid>
                            </Grid>



                            <Border Grid.Row="1" >
                                <StackPanel>
                                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                                        <!--图表缩放.输入框.X轴范围-->
                                        <StackPanel Margin="{StaticResource ControlMargin}" Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgGrid.XRange}" />
                                            <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
                                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" 
                                                 Text="{Binding ZoomInHelper.XRangeSlider.SliderLowerValue,StringFormat={}{0:F0}}" />

                                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="-" />
                                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" 
                                                 Text="{Binding ZoomInHelper.XRangeSlider.SliderUpperValue,StringFormat={}{0:F0}}" />


                                            </StackPanel>
                                        </StackPanel>
                                        <!--图表缩放.输入框.Y轴范围-->
                                        <StackPanel Margin="{StaticResource ControlMargin}" Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgGrid.YRange}" />
                                            <StackPanel Orientation="Horizontal" >
                                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" 
                                                 Text="{Binding ZoomInHelper.YRangeSlider.SliderLowerValue,StringFormat={}{0:F0}}" />
                                                <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="-" />
                                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" 
                                                 Text="{Binding ZoomInHelper.YRangeSlider.SliderUpperValue,StringFormat={}{0:F0}}" />
                                            </StackPanel>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <!--图表缩放.按钮.放大-->
                                            <Button Style="{StaticResource Styles.Button.Icon.Rectangle}"
                                        Command="{Binding ZoomInHelper.ZoomInCmd}" >
                                                <iconPacks:PackIconMaterial Kind="MagnifyPlus" />
                                            </Button>
                                            <!--图表缩放.按钮.缩小-->
                                            <Button Style="{StaticResource Styles.Button.Icon.Rectangle}"
                                        Command="{Binding ZoomInHelper.ZoomOutCmd}" >
                                                <iconPacks:PackIconMaterial Kind="MagnifyMinus" />
                                            </Button>
                                        </StackPanel>
                                    </StackPanel>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="auto"/>
                                        </Grid.ColumnDefinitions>

                                        <StackPanel Orientation="Horizontal" >
                                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="{StaticResource ControlMargin}">
                                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgGrid.IsADMode}" />
                                                <ToggleButton Style="{StaticResource Styles.ToggleButton.Check}" HorizontalAlignment="Left" IsChecked="{Binding IsADMode}" />
                                            </StackPanel>
                                            <Button Content="{StaticResource str.PgGrid.GetForw}" Style="{StaticResource Styles.Button.Square.Accent2}" Command="{Binding GetFDataCmd}" />
                                            <Button Content="{StaticResource str.PgGrid.GetBackw}" Style="{StaticResource Styles.Button.Square2}" Command="{Binding GetBDataCmd}"  />
                                            <Button Content="{StaticResource str.PgGrid.AddSeries}" Style="{StaticResource Styles.Button.Square2}" 
                                Visibility="{Binding CanAddSeries,Converter={StaticResource visbilityconv}}"
                                Command="{Binding AddSeriesCmd}" />
                                            <Button Content="{StaticResource str.PgGrid.RemoveSeries}" Style="{StaticResource Styles.Button.Square2}" 
                                Background="{StaticResource MahApps.Brushes.Validation5}"
                                Foreground="{StaticResource MahApps.Brushes.Selected.Foreground}"
                            
                            Visibility="{Binding CanRemoveSeries,Converter={StaticResource visbilityconv}}"
                                Command="{Binding RemoveSeriesCmd}" />
                                        </StackPanel>
                                        <Button Grid.Column="1" Content="{StaticResource str.PgGrid.Save}" Style="{StaticResource Styles.Button.Square2}" Command="{Binding SaveCmd}" />
                                    </Grid>
                                </StackPanel>

                            </Border>
                        </Grid>
                    </StackPanel>
                </Border>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>