<Page x:Class="FLY.Thick.Base.UI.PgGetSample"
      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:local="clr-namespace:FLY.Thick.Base.UI"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      mc:Ignorable="d" 
      d:DesignHeight="1200" d:DesignWidth="1024"
      Background="WhiteSmoke">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Converter/Dictionary_MyConv.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:GetSampleVmUt x:Key="unittest"/>
            <local:Item2IndexConverter x:Key="i2iConv"/>
            <local:Item2DirectionConverter x:Key="i2dConv"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid d:DataContext="{StaticResource unittest}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition  />
        </Grid.RowDefinitions>
        <Grid Name="grid_initparam"/>
        <StackPanel Orientation="Horizontal" Background="{StaticResource Background_Title}">
            <Button Style="{StaticResource ButtonStyle_back2}" Command="BrowseBack"/>
            <TextBlock Style="{StaticResource TextBlockStyle_Title}"  Text="样品标定"/>
        </StackPanel>
        <ScrollViewer PanningMode="Both" Grid.Row="1" >
            <StackPanel >
                <StackPanel Orientation="Horizontal" >
                    <Border Style="{StaticResource BorderStyle_paramSection}">
                        <TextBlock Text="基本" />
                    </Border>
                    <StackPanel>
                        <StackPanel Margin="{StaticResource ControlMargin}">
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="使能" />
                                    <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding Enable}"/>
                                </StackPanel>
                            </StackPanel>


                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeader}" Text="速度" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" Text="{Binding Velocity}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                                        <Run >
                                            <MultiBinding Converter="{StaticResource outsp2mpminconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                            <Binding Path="Velocity" />
                                            <Binding Path="DataContext.Encoder1_mmpp"  ElementName="grid_initparam"/>
                                            <Binding Path="DataContext.Speed1Scale" ElementName="grid_initparam"/>
                                        </MultiBinding>
                                        </Run>
                                        <Run Text="m/min"/>
                                    </TextBlock>
                                </StackPanel>

                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="样品半径" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Range}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                                        <Run>
                                            <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                <Binding Path="Range" />
                                                <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                            </MultiBinding>
                                        </Run>
                                        <Run Text="mm"/>
                                    </TextBlock>
                                </StackPanel>

                            </StackPanel>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <!--<StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="{StaticResource strSampleInterval}" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Interval}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="min"/>
                                </StackPanel>

                            </StackPanel>-->
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="移动滤波" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Window}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="min"/>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="按%判断异常" />
                                <ToggleButton  Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding IsCheckByPercent}" HorizontalAlignment="Left"/>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}" Visibility="{Binding IsCheckByPercent,Converter={StaticResource visbilityconv}, ConverterParameter=Collapsed}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="异常比例" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding ErrPercent,StringFormat={}{0:F1}}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="%"/>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}" Visibility="{Binding IsCheckByPercent,Converter={StaticResource visbilityconv}, ConverterParameter=CollapsedWhenTrue}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="异常值" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding ErrValue}" />
                                </StackPanel>
                            </StackPanel>
                            <Button Style="{StaticResource ButtonStyle2}"  FontSize="27" Command="{Binding GetOrgAdCmd}">
                                <StackPanel>
                                    <TextBlock Text="计算"/>
                                    <TextBlock Text="原始AD值"/>
                                </StackPanel>
                            </Button>
                            <Button Style="{StaticResource ButtonStyle2}" FontSize="27" Click="btnGageInfoClick">
                                <StackPanel>
                                    <TextBlock Text="机架信息"/>
                                </StackPanel>
                            </Button>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <StackPanel.Resources>
                        <sys:Double x:Key="column0_width">50</sys:Double>
                        <sys:Double x:Key="column_width">150</sys:Double>
                        <Style x:Key="TextBlockStyle_header_no" TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeader}">
                            <Setter Property="Margin" Value="0"/>
                            <Setter Property="Width" Value="{StaticResource column0_width}"/>
                        </Style>
                        <Style x:Key="TextBlockStyle_header" TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeaderEditable}">
                            <Setter Property="Margin" Value="0"/>
                            <Setter Property="Width" Value="{StaticResource column_width}"/>
                            <Setter Property="TextAlignment" Value="Center"/>
                        </Style>
                    </StackPanel.Resources>
                    <Border Style="{StaticResource BorderStyle_paramSection}">
                        <TextBlock Text="样品"/>
                    </Border>
                    <StackPanel>
                        <StackPanel.Resources>
                            <CollectionViewSource Source="{Binding Samples}" x:Key="samplesViewSource" />
                        </StackPanel.Resources>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource TextBlockStyle_header_no}" Text="序号" />
                            <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="使能" />
                            <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="不标定" />
                            <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="原始AD值" />
                            <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="位置" />

                        </StackPanel>
                        <ItemsControl ItemsSource="{Binding Source={StaticResource samplesViewSource}}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <Rectangle Height="2" Fill="Gray"/>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" Width="{StaticResource column0_width}" Margin="0">
                                                <Run Text="{Binding Path=., Mode=OneWay, Converter={StaticResource i2iConv}, ConverterParameter={StaticResource samplesViewSource}}"/>
                                            </TextBlock>
                                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding Enable}" Width="{StaticResource column_width}" Margin="0"/>
                                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding JustForCheck}" Width="{StaticResource column_width}" Margin="0"/>
                                            <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" TextAlignment="Center" Text="{Binding OrgAD}" Width="{StaticResource column_width}" Margin="0"/>
                                            <StackPanel Orientation="Horizontal" >
                                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Position}" />
                                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                                                <Run>
                                                    <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                        <Binding Path="Position" />
                                                        <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                                    </MultiBinding>
                                                </Run>
                                                <Run Text="mm" />
                                                </TextBlock>
                                            </StackPanel>

                                        </StackPanel>
                                    </StackPanel>



                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </StackPanel>


                <StackPanel Orientation="Horizontal">
                    <Border Style="{StaticResource BorderStyle_paramSection}">
                        <TextBlock Text="位置修正" />
                    </Border>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">

                            <StackPanel Margin="{StaticResource ControlMargin}" Orientation="Vertical">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="查找范围" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Search}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}">
                                        <Run>
                                            <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                <Binding Path="Search" />
                                                <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                            </MultiBinding>
                                        </Run>
                                        <Run Text="mm" /></TextBlock>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                        <StackPanel>
                            <StackPanel.Resources>
                                <sys:Double x:Key="column0_width">50</sys:Double>
                                <sys:Double x:Key="column_width">150</sys:Double>
                                <Style x:Key="TextBlockStyle_header_no" TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeader}">
                                    <Setter Property="Margin" Value="0"/>
                                    <Setter Property="Width" Value="{StaticResource column0_width}"/>
                                </Style>
                                <Style x:Key="TextBlockStyle_header" TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeaderEditable}">
                                    <Setter Property="Margin" Value="0"/>
                                    <Setter Property="Width" Value="{StaticResource column_width}"/>
                                    <Setter Property="TextAlignment" Value="Center"/>
                                </Style>
                                <CollectionViewSource Source="{Binding Features}" x:Key="featuresViewSource" />
                            </StackPanel.Resources>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle_header_no}" Text="特征" />
                                <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="使能" />
                                <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="位置" />
                            </StackPanel>
                            <ItemsControl ItemsSource="{Binding Source={StaticResource featuresViewSource}}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <Rectangle Height="2" Fill="Gray"/>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" FontSize="20" Width="{StaticResource column0_width}" Margin="0" VerticalAlignment="Center">
                                                    <Run Text="{Binding Path=., Mode=OneWay, Converter={StaticResource i2dConv},ConverterParameter={StaticResource featuresViewSource}}"/>
                                                </TextBlock>
                                                <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding Enable}" Width="{StaticResource column_width}" Margin="0"/>

                                                <StackPanel Orientation="Horizontal">
                                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding StartPos}" />
                                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" Text="-" />
                                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding EndPos}" />
                                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" />
                                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}">
                                        <Run>
                                            <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                <Binding Path="StartPos" />
                                                <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                            </MultiBinding>
                                        </Run>
                                        <Run Text="mm" />
                                        <Run Text="-" />
                                        <Run>
                                            <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                <Binding Path="EndPos" />
                                                <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                            </MultiBinding>
                                        </Run>
                                        <Run Text="mm" />
                                                    </TextBlock>
                                                </StackPanel>

                                            </StackPanel>
                                        </StackPanel>



                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>


            </StackPanel>
        </ScrollViewer>
        <Button Style="{StaticResource Styles.Button.Apply}" VerticalAlignment="Bottom" Margin="0,0,20,-45" 
                    Command="{Binding ApplyCmd}"/>
    </Grid>
</Page>
