<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:PgGetSampleVmUt x:Key="viewModel"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid d:DataContext="{StaticResource viewModel}" Background="{StaticResource Brushes.Card.Background}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition  />
        </Grid.RowDefinitions>
        <Grid Name="grid_initparam"/>
        <StackPanel Orientation="Horizontal" Background="{StaticResource Brushes.TitleBar.Background}">
            <Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"/>
            <TextBlock Style="{StaticResource Styles.TitleBar.Text}" >
                <Run Text="{Binding InfoName}"/>样品标定
            </TextBlock>
        </StackPanel>
        <ScrollViewer PanningMode="Both" Grid.Row="1" >
            <StackPanel >
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="基本"/>
                        
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel Margin="{StaticResource ControlMargin}">
                                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="使能" />
                                        <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding Enable}"/>
                                    </StackPanel>
                                </StackPanel>


                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="样品半径" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding SampleRange}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                        <Run>
                                            <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                <Binding Path="SampleRange" />
                                                <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                            </MultiBinding>
                                        </Run>mm
                                    </TextBlock>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="移动滤波窗口" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Window}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="min"/>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="按%判断异常" />
                                <ToggleButton  Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding IsCheckByPercent}" HorizontalAlignment="Left"/>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}" Visibility="{Binding IsCheckByPercent,Converter={StaticResource visbilityconv}, ConverterParameter=Collapsed}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="异常比例" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding ErrPercent,Converter={StaticResource percentconv}}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="%"/>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}" Visibility="{Binding IsCheckByPercent,Converter={StaticResource visbilityconv}, ConverterParameter=CollapsedWhenTrue}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="异常AD值" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding ErrValue}" />
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                            <StackPanel Orientation="Horizontal">


                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="差异比例" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding CrossErrPercent,Converter={StaticResource percentconv}}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="%"/>
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" Text="样品1AD/样品0AD&#13;与上一次比较" />
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                        </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="样品"/>
                        <StackPanel Orientation="Horizontal">
                            <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 Styles.Text.FieldHeader}">
                                        <Setter Property="Margin" Value="0"/>
                                        <Setter Property="Width" Value="{StaticResource column0_width}"/>
                                        <Setter Property="TextAlignment" Value="Center"/>
                                    </Style>
                                    <Style x:Key="TextBlockStyle_header" TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldHeader.Editable}">
                                        <Setter Property="Margin" Value="0"/>
                                        <Setter Property="Width" Value="{StaticResource column_width}"/>
                                        <Setter Property="TextAlignment" Value="Center"/>
                                    </Style>
                                </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 Samples}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Visibility="{Binding IsVisible,Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}">
                                                <Rectangle Height="2" Fill="Gray"/>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Width="{StaticResource column0_width}" 
                                                           Text="{Binding Name}"/>
                                                    <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" Width="{StaticResource column_width}" 
                                                              IsChecked="{Binding Enable}" />
                                                    <StackPanel Orientation="Horizontal" Visibility="{Binding Enable,Converter={StaticResource visbilityconv}}">
                                                        <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" Width="{StaticResource column_width}"
                                                              IsChecked="{Binding JustForCheck}" />
                                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Width="{StaticResource column_width}" TextAlignment="Center" 
                                                         Text="{Binding OrgAD}" />
                                                        <Grid Width="{StaticResource column_width}" >
                                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding Position}" />
                                                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" >
                                                            <Run>
                                                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                                    <Binding Path="Position" />
                                                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                                                </MultiBinding>
                                                            </Run>mm
                                                                </TextBlock>
                                                            </StackPanel>
                                                        </Grid>
                                                    </StackPanel>


                                                </StackPanel>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="位置修正"/>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">

                                <StackPanel Margin="{StaticResource ControlMargin}" Orientation="Vertical">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="查找范围" />
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding SearchRange}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" />
                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
                                            <Run>
                                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                    <Binding Path="Search" />
                                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                                </MultiBinding>
                                            </Run>mm
                                        </TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel>
                                    <StackPanel.Resources>
                                        <sys:Double x:Key="column0_width">100</sys:Double>
                                        <sys:Double x:Key="column_width">150</sys:Double>
                                        <Style x:Key="TextBlockStyle_header_no" TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldHeader}">
                                            <Setter Property="Margin" Value="0"/>
                                            <Setter Property="Width" Value="{StaticResource column0_width}"/>
                                            <Setter Property="TextAlignment" Value="Center"/>
                                        </Style>
                                        <Style x:Key="TextBlockStyle_header" TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldHeader.Editable}">
                                            <Setter Property="Margin" Value="0"/>
                                            <Setter Property="Width" Value="{StaticResource column_width}"/>
                                            <Setter Property="TextAlignment" Value="Center"/>
                                        </Style>
                                    </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 Features}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel/>
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel>
                                                    <Rectangle Height="2" Fill="Gray"/>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Width="{StaticResource column0_width}" 
                                                               Text="{Binding Name}"/>
                                                        <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" Width="{StaticResource column_width}" 
                                                                  IsChecked="{Binding Enable}" />
                                                        <StackPanel Orientation="Horizontal" Visibility="{Binding Enable,Converter={StaticResource visbilityconv}}">
                                                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding StartPos}" />
                                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="-" />
                                                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input.Card}" Text="{Binding EndPos}" />
                                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}"/>
                                                            <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}">
                                                            <Run>
                                                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                                    <Binding Path="StartPos" />
                                                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                                                </MultiBinding>
                                                            </Run>mm-
                                                            <Run>
                                                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F0}">
                                                                    <Binding Path="EndPos" />
                                                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                                                </MultiBinding>
                                                            </Run>mm
                                                            </TextBlock>
                                                        </StackPanel>

                                                    </StackPanel>
                                                </StackPanel>



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

                        </StackPanel>

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