<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" 
      xmlns:conv="clr-namespace:FLY.Thick.Base.UI.Converter" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
      mc:Ignorable="d" 
      d:DesignHeight="1200" d:DesignWidth="1024">
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Converter/Converters.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <conv:Pos2mmConverter x:Key="p2mmconv" />
            <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"  >
                <iconPacks:PackIconMaterial Kind="ArrowLeftThick" />
            </Button>
            <TextBlock Style="{StaticResource Styles.TitleBar.Text}" >
                <Run Text="{Binding InfoName}"/><Run Text="{StaticResource str.PgGetSample.Title}"/>
            </TextBlock>
        </StackPanel>
        <ScrollViewer PanningMode="Both" Grid.Row="1" >
            <StackPanel >
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="{StaticResource str.PgGetSample.Base}"/>
                        
                            <StackPanel Margin="{StaticResource ControlMargin}">
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource Styles.Text.FieldHeader.Editable}" Text="{StaticResource str.PgGetSample.Enable}" />
                                        <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="{StaticResource str.PgGetSample.SampleRange}" />
                                <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="{StaticResource str.PgGetSample.Window}" />
                                <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="{StaticResource str.PgGetSample.IsCheckByPercent}" />
                                <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="{StaticResource str.PgGetSample.ErrPercent}" />
                                <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="{StaticResource str.PgGetSample.ErrValue}" />
                                <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="{StaticResource str.PgGetSample.CrossErrPercent}" />
                                <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="{StaticResource str.PgGetSample.CrossErrPercentDesp}" />
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                        </StackPanel>
                </Border>
                <Border Style="{StaticResource Styles.Card.Border}">
                    <StackPanel>
                        <TextBlock Style="{StaticResource Styles.Card.Title}"
                                   Text="{StaticResource str.PgGetSample.Sample}"/>
                        <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="{StaticResource str.PgGetSample.Index}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="{StaticResource str.PgGetSample.Enable}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="{StaticResource str.PgGetSample.JustForCheck}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="{StaticResource str.PgGetSample.OrgAd}" />
                                    <TextBlock Style="{StaticResource TextBlockStyle_header}" Text="{StaticResource str.PgGetSample.Position}" />
                                </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>
            </StackPanel>
        </ScrollViewer>
        <Button Style="{StaticResource Styles.Button.Apply}" VerticalAlignment="Bottom" Margin="0,0,20,20" 
                    Command="{Binding ApplyCmd}"/>
    </Grid>
</Page>
