<UserControl x:Class="HistoryView.Views.Dialogs.ChannelDetail"
             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:HistoryView.Views.Dialogs"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:data="clr-namespace:HistoryView.Data"
             xmlns:Inputs="clr-namespace:HistoryView.Controls.Input"
             xmlns:convert="clr-namespace:HistoryView.Converters"
             xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <convert:AuthorityToVis x:Key="Authority"/>
        <convert:InhibitToBool x:Key="Inhibit"/>
        <convert:AutoTuneStatusToBool x:Key="AutoTuneEnable"/>
        <convert:WorkoutToText x:Key="Workout"/>
        <convert:ActiveTuneSetToVis x:Key="ActiveTuneSet"/>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0"/>
            <RowDefinition/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="4"/>
        </Grid.RowDefinitions>

        <GroupBox Margin="8,4" Header="{DynamicResource ChannelDetailDeviceInfo}">
            <Grid Margin="16,4">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="16"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="16"/>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="16"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <StackPanel>
                    <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left">Mini8:</TextBlock>
                    <TextBox  Grid.Column="2" MinWidth="100" Background="#f8f8f8" Text="{Binding Mini8Info.Name, Mode=OneWay}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"/>
                </StackPanel>

                <StackPanel Grid.Column="2">
                    <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Left">Channel:</TextBlock>
                    <TextBox  Grid.Column="6" MinWidth="100" Background="#f8f8f8" Text="{Binding Channel.Name, Mode=OneWay}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"/>
                </StackPanel>
                <StackPanel Grid.Column="4">
                    <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Left">IsEnable:</TextBlock>
                    <TextBox Grid.Column="10" Text="{Binding Channel.Inhibit}" MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" IsReadOnly="True"  Height="24"/>
                </StackPanel>
                <StackPanel Grid.Column="6">
                    <TextBlock Grid.Column="8" VerticalAlignment="Center" HorizontalAlignment="Left">Mode:</TextBlock>
                    <TextBox Grid.Column="10" Text="{Binding Channel.ChannelMode, Mode=OneWay}" MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" IsReadOnly="True"  Height="24"/>
                </StackPanel>
            </Grid>
        </GroupBox>
        

        <GroupBox Margin="8,4" Grid.Row="4" Header="{DynamicResource ChannelSetting}">
            <TabControl Margin="0,0" BorderBrush="Transparent" Background="Transparent">
                <TabItem Style="{StaticResource TabTheme}" Header="{DynamicResource ChannelDetailActrual}">
                    <Grid Margin="8,4">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="4"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="4"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="4"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="12"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="4"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="0"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Grid Grid.Row="0" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <!--<StackPanel>
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Operation Mode:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.Mode}"/>
                            </StackPanel>-->

                            <StackPanel Grid.Column="0">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">PV:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.PV, StringFormat=0.00}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">SetPoint:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.SetPoint, StringFormat=0.00}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Up Rate:</TextBlock>
                                <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.SetpointUpRate, StringFormat=0.00}"/>
                            </StackPanel>
                            <StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Down Rate:</TextBlock>
                                <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.SetpointDownRate, StringFormat=0.00}"/>
                            </StackPanel>
                            <!--<StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Delay time:</TextBlock>
                                <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.DelayMillionSeconds}"/>
                            </StackPanel>-->
                        </Grid>

                        <Grid Grid.Row="2" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource EmergencyColor}">Floor Limit:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.Floor}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource WarningColor}">Floor Warning:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.FloorWarning}"/>
                            </StackPanel>


                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource WarningColor}">Caps Warning:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.CapsWarning}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource EmergencyColor}">Caps Limit:</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True"  Text="{Binding Channel.Caps}"/>
                            </StackPanel>


                        </Grid>

                        <Grid Grid.Row="4" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Vertical" VerticalAlignment="Center" Width="100">
                                <!--<TextBlock Margin="0,4" VerticalAlignment="Center" >AT Mode</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTuneStatus}"/>-->
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">P :</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.Running_P,Mode=TwoWay, StringFormat=0.00 }"/>
                            </StackPanel>

                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">I :</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.Running_I, StringFormat=0.00}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">D :</TextBlock>
                                <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.Running_D, StringFormat=0.00}"/>
                            </StackPanel>

                            <Image Grid.Column="8" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=Running}" Source="{StaticResource ArrowLeft}" Width="20" Margin="0,0,0,3" VerticalAlignment="Bottom"/>
                        </Grid>

                        <Grid Grid.Row="6" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Vertical" VerticalAlignment="Center" Width="100">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" >AT Mode</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTuneStatus}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Auto Tune P :</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_P,Mode=TwoWay, StringFormat=0.00}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Auto Tune I :</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_I, StringFormat=0.00}"/>
                            </StackPanel>

                            <StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Auto Tune D :</TextBlock>
                                <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_D, StringFormat=0.00}"/>
                            </StackPanel>
                            <Image Grid.Column="8" Source="{StaticResource ArrowLeft}" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=AutoTune}"  Width="20" Margin="0,0,0,3" VerticalAlignment="Bottom"/>

                        </Grid>

                        <Grid Grid.Row="8" Margin="4,0">
                            <Grid Grid.Column="0" VerticalAlignment="Center" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="16"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="36"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">Working Output:</TextBlock>
                                <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Panel.ZIndex="1" >
                                    <Run Text="{Binding Channel.WorkingOutput, StringFormat=0.0}"/>
                                    <Run> %</Run>
                                </TextBlock>
                                <ProgressBar Grid.Column="2" Height="14" VerticalAlignment="Center" Style="{StaticResource ThemeProgressBar}" Value="{Binding Channel.WorkingOutput}"/>
                            </Grid>
                        </Grid>

                        <ContentControl Grid.Row="10" Margin="-8,-5,-8,-10" Content="{Binding PlotHelper.PlotControl, Mode=OneTime}" Height="245"/>

                        <Grid Grid.Row="12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Button Grid.Column="0" Style="{StaticResource FunctionButton}" Command="{Binding ViewHistoryCommand}" MinWidth="100" Height="32">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{StaticResource Log_Icon}" Height="16" Margin="4,2"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,2" Text="{DynamicResource ChannelDetailHistory}"/>
                                </StackPanel>
                            </Button>

                            <Button Grid.Column="2" Style="{StaticResource FunctionButton}" Command="{Binding ExitCommand}" Background="Gray" MinWidth="100" Height="32">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{StaticResource Icon_Reset}" Height="16" Margin="4,2"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,2" Text="{DynamicResource Retrun}"/>
                                </StackPanel>
                            </Button>
                        </Grid>
                    </Grid>
                </TabItem>

                <TabItem Style="{StaticResource TabTheme}" Header="{DynamicResource ChannelDetailTarget}" Visibility="{Binding UserInfo.Authority, Converter={StaticResource Authority}, ConverterParameter=Operator}">
                    <Grid Margin="8">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="8"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="8"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="8"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="0"/>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="48"/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <Grid Grid.Row="0" Margin="0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="4"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                            <GroupBox Header="Channel Enable:" >
                                <Grid Grid.Row="0" Margin="0,4">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Button Grid.Column="0" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding EnableChannelCommand}" CommandParameter="Enable" MinWidth="100">
                                        <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center">Enable</TextBlock>
                                    </Button>

                                    <Button Grid.Column="2" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding EnableChannelCommand}" Background="{StaticResource EmergencyColor}" CommandParameter="Disable" MinWidth="100">
                                        <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center"  >Disable</TextBlock>
                                    </Button>
                                </Grid>
                            </GroupBox>

                            <GroupBox Header="Channel Mode:" Grid.Column="2">
                                <Grid Grid.Row="0" Margin="0,4">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Button Grid.Column="0" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding EnableChannelCommand}" CommandParameter="Control" MinWidth="100">
                                        <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center">Control</TextBlock>
                                    </Button>

                                    <Button Grid.Column="2" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding EnableChannelCommand}" CommandParameter="Monitor" MinWidth="100">
                                        <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center">Monitor</TextBlock>
                                    </Button>
                                </Grid>
                            </GroupBox>

                        </Grid>

                        <Grid Grid.Row="2" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <!--<StackPanel Grid.Column="0">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Operation Mode:</TextBlock>
                                <ComboBox Grid.Column="6" MinWidth="100" Background="#f8f8f8" 
                                          ItemsSource="{Binding Source={StaticResource ChannelModeEnum}}" 
                                          SelectedItem="{Binding ChannelSet.Mode, Mode=TwoWay}"/>
                            </StackPanel>-->

                            <StackPanel Grid.Column="0">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">SetPoint:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.SetPoint, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  
                                                  Text="{Binding ChannelSet.SetPoint, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">UpRate:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.SetpointUpRate, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  
                                                  Text="{Binding ChannelSet.SetpointUpRate, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">DownRate:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.SetpointDownRate, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  
                                                  Text="{Binding ChannelSet.SetpointDownRate, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                            <!--<StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">Delay time:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.DelayMillionSeconds, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.DelayMillionSeconds, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>-->
                        </Grid>

                        <Grid Grid.Row="4" Margin="4,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource EmergencyColor}">Floor Limit:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.Floor, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.Floor, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                            <StackPanel Grid.Column="2">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource WarningColor}">Floor Warning:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.FloorWarning, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.FloorWarning, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>


                            <StackPanel Grid.Column="4">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource WarningColor}">Caps Warning:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.CapsWarning, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.CapsWarning, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                            <StackPanel Grid.Column="6">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="{StaticResource EmergencyColor}">Caps Limit:</TextBlock>
                                <Inputs:NumberKeyboard Text="{Binding ChannelSet.Caps, Mode=TwoWay}">
                                    <Inputs:NumberKeyboard.DisplayContent>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.Caps, Mode=TwoWay}"/>
                                    </Inputs:NumberKeyboard.DisplayContent>
                                </Inputs:NumberKeyboard>
                            </StackPanel>

                        </Grid>

                        <!--<Grid Grid.Row="6" Margin="4,0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="4"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Margin="0,4" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Left">Working Output (%):</TextBlock>
                            <TextBlock Margin="0,4" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Right">0% - No Limit</TextBlock>

                            <Inputs:NumberKeyboard Grid.Row="2" Grid.Column="0" Text="{Binding ChannelSet.WorkingOutput, Mode=TwoWay}">
                                <Inputs:NumberKeyboard.DisplayContent>
                                    <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.WorkingOutput, Mode=TwoWay , StringFormat=0.00}"/>
                                </Inputs:NumberKeyboard.DisplayContent>
                            </Inputs:NumberKeyboard>
                            <Slider Grid.Row="2" Grid.Column="2" TickFrequency="1"  Style="{StaticResource MySliderStyle}" VerticalAlignment="Center" Maximum="100" Value="{Binding ChannelSet.WorkingOutput, Mode=TwoWay}"/>
                        </Grid>-->

                        <Grid Grid.Row="8">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="12"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="6"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="16"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="8"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <Button Grid.Column="0" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding EnableATCommand}" Width="100">
                                <StackPanel>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">Start</TextBlock>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">AutoTune</TextBlock>
                                </StackPanel>
                            </Button>

                            <GroupBox Grid.Row="0" Grid.Column="2" Header="Running PID :">
                                <Grid Margin="4">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <StackPanel Grid.Column="0">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">P :</TextBlock>
                                        <Inputs:NumberKeyboard Text="{Binding ChannelSet.Running_P, Mode=TwoWay}">
                                            <Inputs:NumberKeyboard.DisplayContent>
                                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.Running_P, Mode=TwoWay , StringFormat=0.00}"/>
                                            </Inputs:NumberKeyboard.DisplayContent>
                                        </Inputs:NumberKeyboard>
                                    </StackPanel>

                                    <StackPanel Grid.Column="2">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">I :</TextBlock>
                                        <Inputs:NumberKeyboard Text="{Binding ChannelSet.Running_I, Mode=TwoWay }">
                                            <Inputs:NumberKeyboard.DisplayContent>
                                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.Running_I, Mode=TwoWay , StringFormat=0.00}"/>
                                            </Inputs:NumberKeyboard.DisplayContent>
                                        </Inputs:NumberKeyboard>
                                    </StackPanel>

                                    <StackPanel Grid.Column="4">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">D :</TextBlock>
                                        <Inputs:NumberKeyboard Text="{Binding ChannelSet.Running_D, Mode=TwoWay}">
                                            <Inputs:NumberKeyboard.DisplayContent>
                                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24"  Text="{Binding ChannelSet.Running_D, Mode=TwoWay , StringFormat=0.00}"/>
                                            </Inputs:NumberKeyboard.DisplayContent>
                                        </Inputs:NumberKeyboard>
                                    </StackPanel>
                                </Grid>
                            </GroupBox>

                            <Button Grid.Column="4" VerticalAlignment="Center" HorizontalContentAlignment="Center" Width="32" Height="32"
                                    Command="{Binding SelectPIDCommand}" CommandParameter="Running">

                                <Image Source="{StaticResource ArrowLeft}" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=Running}"  Width="20" Margin="0,0,0,0" VerticalAlignment="Center"/>
                            </Button>

                            <Button Grid.Row="2" Grid.Column="0" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding AbortATCommand}" Background="{StaticResource WarningColor}" Width="100">
                                <TextBlock Margin="2" VerticalAlignment="Center" HorizontalAlignment="Center">Abort</TextBlock>
                            </Button>


                            <Button Grid.Row="2" Grid.Column="2" Style="{StaticResource FunctionButton}" VerticalAlignment="Center" HorizontalAlignment="Center" Command="{Binding ApplyPIDCommand}" >
                                <TextBlock Margin="2" IsEnabled="{Binding Channel.AutoTuneStatus, Converter={StaticResource AutoTuneEnable}}">Apply AutoTune PID ↑↑</TextBlock>
                            </Button>

                            <StackPanel Grid.Column="0" Grid.Row="4" Orientation="Vertical" VerticalAlignment="Center">
                                <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Center">AutoTune Status</TextBlock>
                                <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTuneStatus}"/>
                            </StackPanel>

                            <!--<GroupBox Grid.Row="4" Grid.Column="2" Header="{DynamicResource ChannelDetailActrual}">-->
                            <GroupBox Grid.Row="4" Grid.Column="2" Header="AutoTune PID :">
                                <Grid Margin="4">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="16"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <StackPanel Grid.Column="0">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">P :</TextBlock>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_P, StringFormat=0.00}"/>
                                    </StackPanel>

                                    <StackPanel Grid.Column="2">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">I :</TextBlock>
                                        <TextBox  MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_I, StringFormat=0.00}"/>
                                    </StackPanel>

                                    <StackPanel Grid.Column="4">
                                        <TextBlock Margin="0,4" VerticalAlignment="Center" HorizontalAlignment="Left">D :</TextBlock>
                                        <TextBox MinWidth="100" Background="#f8f8f8" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderThickness="0" Height="24" IsReadOnly="True" Text="{Binding Channel.AutoTune_D, StringFormat=0.00}"/>
                                    </StackPanel>
                                </Grid>
                            </GroupBox>

                            <Button Grid.Row="4" Grid.Column="4" VerticalAlignment="Center" HorizontalContentAlignment="Center" Width="32" Height="32"
                                    Command="{Binding SelectPIDCommand}" CommandParameter="Autotune">
                                <Image Source="{StaticResource ArrowLeft}" Visibility="{Binding Channel.ActiveTuneSet, Converter={StaticResource ActiveTuneSet}, ConverterParameter=AutoTune}"  Width="20" Margin="0,0,0,0" VerticalAlignment="Center"/>
                            </Button>
                        </Grid>

                        <Grid Grid.Row="10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="0"/>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>

                            <!--<Button Grid.Column="0" Style="{StaticResource FunctionButton}" Command="{Binding OperateCommand}" CommandParameter="Save" MinWidth="100" Height="32">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{StaticResource application_recordDrawingImage}" Height="16" Margin="4,2"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,2" Text="{DynamicResource Save}"/>
                                </StackPanel>
                            </Button>-->

                            <Button Grid.Column="2" Style="{StaticResource FunctionButton}" Command="{Binding OperateCommand}" CommandParameter="Send" MinWidth="100" Height="32">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{StaticResource Icon_Start}" Height="16" Margin="4,2"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,2" Text="{DynamicResource ChannelDetailSend}"/>
                                </StackPanel>
                            </Button>

                            <Button Grid.Column="4" Style="{StaticResource FunctionButton}" Command="{Binding ExitCommand}" MinWidth="100" Height="32" Background="Gray">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{StaticResource Icon_Reset}" Height="16" Margin="4,2"/>
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,2" Text="{DynamicResource Retrun}"/>
                                </StackPanel>
                            </Button>
                        </Grid>
                    </Grid>
                </TabItem>
            </TabControl>
        </GroupBox>


    </Grid>
</UserControl>
