<Page x:Class="FLY.Thick.FilmCasting.UI.PgProfile"
      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.FilmCasting.UI"
      xmlns:common="clr-namespace:FLY.Thick.FilmCasting.Common;assembly=FLY.Thick.FilmCasting"
      mc:Ignorable="d" 
      d:DesignHeight="1024" d:DesignWidth="1280" Background="WhiteSmoke"
      d:DataContext="{d:DesignInstance local:PgProfileVm}"
	    x:Name="page">
    <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>
            <Style TargetType="GroupBox"/>
            <common:FilmCastingProfileParam x:Key="param" />
        </ResourceDictionary>
    </Page.Resources>

    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="496*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid x:Name="grid_root"/>
        <StackPanel Orientation="Horizontal">
            <Button Style="{StaticResource Styles.TitleBar.BackButton}" Command="BrowseBack"/>
            <TextBlock Style="{StaticResource Styles.TitleBar.Text2}" >
                <Run Text="产品工艺表"/>
                <StackPanel DataContext="{Binding DynArea}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="测试模式"/>
                        <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" Text="+100"/>
                    </StackPanel>
                    
                    <ToggleButton Style="{StaticResource Styles.ToggleButton.YESNO}" IsChecked="{Binding IsTest}"/>
                </StackPanel>
            </TextBlock>
        </StackPanel>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="338*" />
            </Grid.ColumnDefinitions>
            <Grid x:Name="grid_dynarea" d:DataContext="{Binding DynArea}"/>
            <ScrollViewer MinWidth="550" d:DataContext="{StaticResource param}" DataContext="{Binding Param}">
                <StackPanel Name="groupbox_profile">
                    <StackPanel Orientation="Horizontal" >
                        <Border Style="{StaticResource Styles.ParamSection.Border}">
                            <Viewbox>
                                <TextBlock Text="产品" />
                            </Viewbox>
                        </Border>
                        <StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="名称" />
                                <Viewbox Margin="2" Width="350" Height="40" HorizontalAlignment="Left">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding PName}" Tag="Full" />
                                </Viewbox>
                            </StackPanel>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="auto"/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="订单号" />
                                    <Viewbox Margin="2" Width="300" Height="40" HorizontalAlignment="Left">
                                        <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Batch}" Tag="Full" />
                                    </Viewbox>
                                </StackPanel>
                                <StackPanel Margin="{StaticResource ControlMargin}" Grid.Column="1">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="卷号" />
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Number}" />
                                </StackPanel>
                            </Grid>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" >
                        <Border Style="{StaticResource Styles.ParamSection.Border}">
                            <TextBlock Text="工艺" />
                        </Border>
                        <StackPanel Orientation="Horizontal" >
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="目标值" />
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Target, StringFormat={}{0:F2}}" />
                            </StackPanel>
                            <StackPanel Margin="{StaticResource ControlMargin}" >
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="公差%" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding TolerancePercent, Converter={StaticResource percentconv}}" />
                                    <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="%" />
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" >
                        <Button Style="{StaticResource Styles.ParamSection.Button}" Command="{Binding DataContext.AhelperCmd,ElementName=page}">
                            <TextBlock Text="补偿" />
                        </Button>
                        <StackPanel Margin="{StaticResource ControlMargin}">
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="斜率K" />
                            <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding K, StringFormat={}{0:F3}}" />
                        </StackPanel>
                        <StackPanel Margin="{StaticResource ControlMargin}" Visibility="{Binding ElementName=grid_dynarea,Path=DataContext.IsTest,Converter={StaticResource visbilityconv}}">
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="平移B" />
                            <TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="{Binding B, StringFormat={}{0:F2}}" />
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Border Style="{StaticResource Styles.ParamSection.Border}" >
                            <TextBlock Text="范围" />
                        </Border>
                        <StackPanel Margin="{StaticResource ControlMargin}" >
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="显示范围" />
                                <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Comment}" DataContext="{Binding ElementName=grid_root,Path=DataContext}">
                                    最大<Run Text="{Binding Boltmap.BoltCnt}"/>分区
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" DataContext="{Binding ElementName=grid_root,Path=DataContext.ScanRange}">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Begin}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="分区" />
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" Text="~" />
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding End}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="分区" />
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Margin="{StaticResource ControlMargin}" DataContext="{Binding ElementName=grid_root,Path=DataContext.DataRange}">
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="数据范围" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding Begin}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="分区" />
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Separator}" Text="~" />
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding End}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="分区" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Border Style="{StaticResource Styles.ParamSection.Border}" >
                            <TextBlock Text="分区" />
                        </Border>
                        <StackPanel Margin="{StaticResource ControlMargin}" >
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable.Row2}" Text="开始无效螺丝数" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding LeftEmptyBolts}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="个" />
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Margin="{StaticResource ControlMargin}" >
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable.Row2}" Text="结束无效螺丝数" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding RightEmptyBolts}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="个" />
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Margin="{StaticResource ControlMargin}" >
                            <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="收缩率" />
                            <StackPanel Orientation="Horizontal">
                                <TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding UniformShrinkPercent,Converter={StaticResource percentconv}}"/>
                                <TextBlock Style="{StaticResource Styles.Text.FieldContent.Unit}" Text="%" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
            <ListBox Margin="{StaticResource ControlMargin}" MinWidth="400" Grid.Column="1" Background="{StaticResource Brushes.Activity}"
                     SelectedItem="{Binding SelectedItem}"
                     ItemsSource="{Binding ProfileList}">
                <ListBox.Resources>
                    <Style x:Key="FocusVisual">
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle Margin="0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="0" StrokeDashArray="1 2"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                    <SolidColorBrush x:Key="Item.MouseOver.Background" Color="Transparent"/>
                    <SolidColorBrush x:Key="Item.MouseOver.Foreground" Color="White"/>
                    <SolidColorBrush x:Key="Item.MouseOver.Border" Color="#FF3B3B3B"/>

                    <SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="#FF3B3B3B"/>
                    <SolidColorBrush x:Key="Item.SelectedInactive.Foreground" Color="White"/>
                    <SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="#FF3B3B3B"/>

                    <SolidColorBrush x:Key="Item.SelectedActive.Background" Color="LightGray"/>
                    <SolidColorBrush x:Key="Item.SelectedActive.Foreground" Color="Black"/>
                    <SolidColorBrush x:Key="Item.SelectedActive.Border" Color="LightGray"/>

                    <Style  TargetType="{x:Type ListBoxItem}">
                        <Setter Property="FontFamily" Value="Microsoft YaHei UI Light"/>
                        <Setter Property="FontSize" Value="16"/>
                        <!--<Setter Property="HorizontalContentAlignment" Value="Center"/>-->

                        <Setter Property="SnapsToDevicePixels" Value="True"/>
                        <Setter Property="Padding" Value="4,1"/>
                        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                        <Setter Property="Background" Value="Transparent"/>
                        <Setter Property="BorderBrush" Value="Transparent"/>
                        <Setter Property="BorderThickness" Value="1"/>
                        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                                        <!--<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />-->
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock x:Name="Tb" Text="{Binding .}" Foreground="White" FontWeight="Bold" FontSize="26" FontFamily="Microsoft Sans Serif" />
                                        </StackPanel>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="IsMouseOver" Value="True"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.MouseOver.Background}"/>
                                            <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.MouseOver.Border}"/>
                                            <Setter Property="Foreground" TargetName="Tb" Value="{StaticResource Item.MouseOver.Foreground}"/>
                                        </MultiTrigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="Selector.IsSelectionActive" Value="False"/>
                                                <Condition Property="IsSelected" Value="True"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Background}"/>
                                            <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Border}"/>
                                            <Setter Property="Foreground" TargetName="Tb" Value="{StaticResource Item.SelectedInactive.Foreground}"/>
                                        </MultiTrigger>
                                        <MultiTrigger>
                                            <MultiTrigger.Conditions>
                                                <Condition Property="Selector.IsSelectionActive" Value="True"/>
                                                <Condition Property="IsSelected" Value="True"/>
                                            </MultiTrigger.Conditions>
                                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/>
                                            <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/>
                                            <Setter Property="Foreground" TargetName="Tb" Value="{StaticResource Item.SelectedActive.Foreground}"/>
                                        </MultiTrigger>
                                        <Trigger Property="IsEnabled" Value="False">
                                            <Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.Resources>

            </ListBox>
        </Grid>

        <StackPanel Orientation="Horizontal"  Grid.Row="2" HorizontalAlignment="Right" Margin="0,10,-6,10">
            <Button Content="应用" Style="{StaticResource Styles.Button2}" Command="{Binding ApplyCmd}" />
            <Button Content="读取" Style="{StaticResource Styles.Button2}" Command="{Binding ReadCmd}" />
            <Button Content="删除" Style="{StaticResource Styles.Button2}" Command="{Binding DelCmd}"/>
        </StackPanel>
    </Grid>
</Page>

