<Page x:Class="FLY.Thick.Base.UI.PgBorderSearch"
      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:Chr="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
      xmlns:local ="clr-namespace:FLY.Thick.Base.UI"
      xmlns:misc="clr-namespace:Misc;assembly=MISC"
      mc:Ignorable="d" 
      d:DesignHeight="727" d:DesignWidth="1280"
      d:DataContext="{d:DesignInstance local:PgBorderSearchVm}"
      x:Name="root"
      Background="WhiteSmoke"
	Title="Page_BorderSearch">
    <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>
        </ResourceDictionary>
    </Page.Resources>
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="496*" />
        </Grid.RowDefinitions>
        <Grid Name="grid_initparam" DataContext="{Binding InitParamService}"/>
        <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>
            <local:CtMicroGage Grid.Column="1" x:Name="mircoGage" Background="Transparent" VerticalAlignment="Bottom"/>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="496*" />
            </Grid.RowDefinitions>
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Button Style="{StaticResource ButtonStyle_paramSection}" Command="{Binding  ApplyCmd}" >
                    <TextBlock Text="参数&#x0a;应用"/>
                </Button>
                <StackPanel Grid.Column="1">

                    <StackPanel Margin="5" Visibility="{Binding DataContext.HasHold, ElementName=grid_initparam, Converter={StaticResource visbilityconv}, ConverterParameter=Collapsed}">
                        <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="有效范围" />
                        <StackPanel Orientation="Horizontal">
                            <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Valid.Begin}" />
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" Text="-"/>
                            <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding Valid.End}" MinWidth="30" MaxWidth="120"/>
                            <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="Valid.Begin" />
                                    <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="Valid.End" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                            </TextBlock>
                        </StackPanel>

                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="使能" />
                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding Enable}" HorizontalAlignment="Left"/>
                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="拐点查找" />
                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding IsBreakDetect}" HorizontalAlignment="Left"/>
                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="设置温修" />
                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding TempADBySet}" HorizontalAlignment="Left"/>
                        </StackPanel>
                        <Grid>
                            <StackPanel  Margin="5" Visibility="{Binding TempADBySet, Converter={StaticResource visbilityconv},ConverterParameter=CollapsedWhenTrue}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeader}" Text="温修AD" />
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}" Text="{Binding TempAD}" />
                            </StackPanel>
                            <StackPanel  Margin="5" Visibility="{Binding TempADBySet, Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="温修AD" />
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding TempAD}" />
                            </StackPanel>
                        </Grid>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="温修范围%" />
                            <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding IsTempRangeByPercent}" HorizontalAlignment="Left"/>
                        </StackPanel>
                        <StackPanel Margin="5" >
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="温修范围" />
                            <Grid>
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding TempRange}" Visibility="{Binding IsTempRangeByPercent, Converter={StaticResource visbilityconv},ConverterParameter=CollapsedWhenTrue}"/>
                                <StackPanel Orientation="Horizontal" Visibility="{Binding IsTempRangeByPercent, Converter={StaticResource visbilityconv},ConverterParameter=Collapsed}">
                                    <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding TempRangePercent,Converter={StaticResource percentconv}}"/>
                                    <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" Text="%"/>
                                </StackPanel>
                            </Grid>
                        </StackPanel>

                    </StackPanel>
                    <WrapPanel Orientation="Horizontal">
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="滤波器" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding N}" />
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|"/>
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                            <Run >
                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                    <Binding Path="N" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>


                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="探头直径" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding SensorWidth}" />
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|"/>
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                            <Run >
                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                        <Binding Path="SensorWidth" />
                                        <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                    </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>


                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="边界内缩" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding N2}" />
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|"/>
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                            <Run >
                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                        <Binding Path="N2" />
                                        <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                    </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>


                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="边界外扩" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding N3}" />
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|"/>
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" >
                            <Run >
                                <MultiBinding Converter="{StaticResource p2mmconv}" Mode="OneWay" StringFormat="{}{0:F1}">
                                        <Binding Path="N3" />
                                        <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                    </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>


                        </StackPanel>
                    </WrapPanel >
                </StackPanel >


            </Grid>
            <Grid Grid.Row="1" DataContext="{Binding BorderSearchService}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <Border Style="{StaticResource BorderStyle_paramSection}">
                    <TextBlock Text="结果"/>
                </Border>
                <Grid Grid.Column="1" Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <WrapPanel Grid.Column="1" Orientation="Horizontal">
                        <StackPanel  Margin="5">
                            <TextBlock Text="正向边界" >
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeader}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding DataContext.Direction,ElementName=root}" Value="{x:Static misc:DIRECTION.FORWARD}">
                                                <Setter Property="Foreground" Value="Red"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}">
                        <Run Text="{Binding Border_Forw.Begin, Converter={StaticResource intconv}, Mode=OneWay}"/>
                        <Run Text="-"/>
                        <Run Text="{Binding Border_Forw.End, Converter={StaticResource intconv}, Mode=OneWay}"/>
                                </TextBlock>
                                <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="Border_Forw.Begin" />
                                    <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="Border_Forw.End" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>

                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Text="反向边界" >
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockStyle_FieldHeader}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding DataContext.Direction,ElementName=root}" Value="{x:Static misc:DIRECTION.BACKWARD}">
                                                <Setter Property="Foreground" Value="Red"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}">
                        <Run Text="{Binding Border_Backw.Begin, Converter={StaticResource intconv}, Mode=OneWay}"/>
                        <Run Text="-"/>
                        <Run Text="{Binding Border_Backw.End, Converter={StaticResource intconv}, Mode=OneWay}"/>
                                </TextBlock>
                                <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="Border_Backw.Begin" />
                                    <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="Border_Backw.End" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>

                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeader}" Text="膜宽" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}">
                                <Run Text="{Binding Width,Mode=OneWay}"/>
                                </TextBlock>
                                <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="Width" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>

                        </StackPanel>
                        <StackPanel  Margin="5">
                            <TextBlock Style="{StaticResource TextBlockStyle_FieldHeader}" Text="期望膜宽" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockStyle_FieldContent}">
                                <Run Text="{Binding ProductWidth,Mode=OneWay}"/>
                                </TextBlock>
                                <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="ProductWidth" />
                                    <Binding Path="DataContext.Encoder1_mmpp" ElementName="grid_initparam"/>
                                </MultiBinding>
                            </Run>
                            <Run Text="mm"/>
                                </TextBlock>
                            </StackPanel>

                        </StackPanel>
                    </WrapPanel>
                    <WindowsFormsHost Grid.Row="1" Margin="5">
                        <Chr:Chart x:Name="chart1"/>
                    </WindowsFormsHost>
                </Grid>


            </Grid>
        </Grid>

    </Grid>
</Page>
