<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:oxy="http://oxyplot.org/wpf"
        xmlns:local="clr-namespace:VSview"
        xmlns:conv ="clr-namespace:Converters"
        xmlns:cont ="clr-namespace:CustomControls"

        xmlns:CustomControls="clr-namespace:VSview.View.CustomControls" x:Class="VSview.MainWindow"
        Title="VS View" 
        mc:Ignorable ="d" 
        
        d:DataContext="{d:DesignInstance {x:Type local:DesignViewModel}, IsDesignTimeCreatable=True}"  
        
        WindowStartupLocation="CenterScreen" ResizeMode="CanResize" Width="1366" Height="768"
        MinWidth="1366" MinHeight="768" WindowStyle="None"  WindowState="Normal">

    <Window.Resources>

        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VSview;component/View/Resources/Styles/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!--Converts Int to Visibility 1 = Visible, 0 = invisible-->
            <conv:IntToVisibilityConverter x:Key="IntToVisibility"/>

            <!--Converts Int to Bolean 1 = true, 0 = false-->
            <conv:IntToBooleanConverter x:Key="IntToBoolean"/>

            <!--Converts Int to Enabled, 0 = disabled, 1 = Enabled - used for buttons-->
            <conv:IntToEnabledConverter x:Key="IntToEnabled"/>

            <!--Converts Int to preheat time - adds "minute" to the number-->
            <conv:IntToPreheatConverter x:Key="IntToPreheat"/>

            <!--Converts boolean to its inverted value-->
            <conv:InvertBooleanConverter x:Key="InvertBool"/>

            <!--Converts boolean to Visibility string - true - Visible, false- Hidden -->
            <conv:BoolToVisibilityConverter x:Key="BoolToVisibility"/>

        </ResourceDictionary>

    </Window.Resources>

    <WindowChrome.WindowChrome>
        <WindowChrome      
             
            CaptionHeight="0"
        GlassFrameThickness="0"
        ResizeBorderThickness="3" />
    </WindowChrome.WindowChrome>

    <Grid Margin="0,0,0,0" Background="#FF4D5664">

        <Rectangle Fill="Transparent" Height="50" Stroke="Transparent" VerticalAlignment="Top" Margin="831,0,155,0">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewMouseDown">
                    <i:InvokeCommandAction Command="{Binding WindowCommands[MoveWindow]}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Rectangle>

        <TabControl x:Name="MainScreenTab" Background="#FFE9E9E9" SelectedIndex="{Binding MeasurementViewModel.TabcontrolIndex}">

            <!--*****************************************************************************************************************************************-->
            <!--******************************************************************    MEASURMENT   ******************************************************-->
            <!--*****************************************************************************************************************************************-->






            <!--#region Measurement-->
            <TabItem x:Name="MEASURMENT" Header="{DynamicResource HeaderMeasurement}"  Margin="12,5,-12,-2.5" Width="170" Height="50" >

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="180"/>
                        <ColumnDefinition Width="839*"/>
                        <ColumnDefinition Width="250"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="157.5"/>
                        <RowDefinition Height="101.5"/>
                        <RowDefinition Height="56.5"/>
                        <RowDefinition Height="157.5"/>
                        <RowDefinition Height="157.5"/>
                        <RowDefinition Height="30*"/>
                        <RowDefinition Height="65"/>
                    </Grid.RowDefinitions>

                    <!--Backgrounds-->
                    <!--Detector state background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelDetectorSate}" HeaderHeight="50" HeaderPosition="Center" Grid.RowSpan="2" Margin="2" />

                    <!--Detector reject points background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelRejectSetpoints}" HeaderHeight="50" HeaderPosition="Center" Grid.Row="2" Grid.RowSpan="3" Margin="2"/>

                    <!--Display 1 background-->
                    <cont:BackgroudBox HeaderHeight="40" HeaderPosition="Center" Grid.Row="0" Grid.Column="2" Margin="2"/>

                    <!--Display 2 background-->
                    <cont:BackgroudBox HeaderHeight="40" HeaderPosition="Center" Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Margin="2"/>

                    <!--Display 3 background-->
                    <cont:BackgroudBox HeaderHeight="40" HeaderPosition="Center" Grid.Row="3" Grid.Column="2" Margin="2"/>

                    <!--Display 4 background-->
                    <cont:BackgroudBox HeaderHeight="40" HeaderPosition="Center" Grid.Row="4" Grid.Column="2" Margin="2"/>


                    <!--Background headers-->

                    <!--Shown values-->

                    <!--Diodes-->

                    <!-- Display 1 -->
                    <TextBox x:Name="Analog_1"  Margin="10,45,10,0" Text="{Binding MeasurementViewModel.Displays[0].Value, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="105" VerticalAlignment="Top">
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextboxROstyle}">
                                <Setter Property="FontSize" Value="45"/>
                            </Style>
                        </TextBox.Style>
                    </TextBox>

                    <cont:TransparentCombobox Grid.Column="3" Grid.Row="0" HorizontalAlignment="Left" Margin="15,2,0,0" VerticalAlignment="Top" Width="217" Height="38"
                                              ItemsSource="{Binding MeasurementViewModel.DisplayList}" SelectedIndex="{Binding MeasurementViewModel.Displays[0].Selection}" />

                    <!--Display 2-->
                    <TextBox x:Name="Analog_2"  Margin="10,45.5,10,0" Text="{Binding MeasurementViewModel.Displays[1].Value, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="105" VerticalAlignment="Top" Grid.Row="1" Grid.RowSpan="2">
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextboxROstyle}">
                                <Setter Property="FontSize" Value="45"/>
                            </Style>
                        </TextBox.Style>
                    </TextBox>

                    <cont:TransparentCombobox Grid.Column="3" Grid.Row="1" HorizontalAlignment="Left" Margin="15,2.5,0,0" VerticalAlignment="Top" Width="217" Height="38"
                                              ItemsSource="{Binding MeasurementViewModel.DisplayList}" SelectedIndex="{Binding MeasurementViewModel.Displays[1].Selection}" />
                    <!--Display 3-->
                    <TextBox x:Name="Analog_3"  Margin="10,45.5,10,0" Text="{Binding MeasurementViewModel.Displays[2].Value, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Grid.Row="3" Height="105" VerticalAlignment="Top" >
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextboxROstyle}">
                                <Setter Property="FontSize" Value="45"/>
                            </Style>
                        </TextBox.Style>
                    </TextBox>

                    <cont:TransparentCombobox Grid.Column="3" Grid.Row="3" HorizontalAlignment="Left" Margin="15,3,0,0" VerticalAlignment="Top" Width="217" Height="38"
                                              ItemsSource="{Binding MeasurementViewModel.DisplayList}" SelectedIndex="{Binding MeasurementViewModel.Displays[2].Selection}" />

                    <!--Display 4-->
                    <TextBox x:Name="Analog_4"  Margin="10,44.5,9,0" Text="{Binding MeasurementViewModel.Displays[3].Value, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Grid.Row="4" Height="105" VerticalAlignment="Top" >
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextboxROstyle}">
                                <Setter Property="FontSize" Value="45"/>
                            </Style>
                        </TextBox.Style>
                    </TextBox>

                    <cont:TransparentCombobox Grid.Column="3" Grid.Row="4" HorizontalAlignment="Left" Margin="15,1.5,0,0" VerticalAlignment="Top" Width="217" Height="38"
                                              ItemsSource="{Binding MeasurementViewModel.DisplayList}" SelectedIndex="{Binding MeasurementViewModel.Displays[3].Selection}" />


                    <!--Labels and diodes-->
                    <Label x:Name="ConnectionStatus_lbl" Content="{DynamicResource LabelConnection}" Margin="10,60,0,0" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="126" />
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,60,0,0" VerticalAlignment="Top" Width="50" Height="50" RedLight="{Binding Detector.Settings.IsConnected, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Settings.IsConnected}" />

                    <Label x:Name="CalibrationStatus_lbl" Content="{DynamicResource LabelCalibration}" Margin="10,120,44,0" VerticalAlignment="Top" Grid.RowSpan="2" Height="50" />
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,120,0,0" VerticalAlignment="Top" Width="50" Height="50" GrayLight="{Binding Detector.Settings.IsConnected, Converter={StaticResource InvertBool}}"  RedLight="{Binding Detector.Calibration.CalibrationStatus, Converter={StaticResource InvertBool},  diag:PresentationTraceSources.TraceLevel=High}" GreenLight="{Binding Detector.Calibration.CalibrationStatus}" Grid.RowSpan="2"/>

                    <Label x:Name="Reject1Active_lbl" Content="{DynamicResource LabelReject1}" Margin="10,10,0,0"  HorizontalAlignment="Left" Width="148" Height="50" VerticalAlignment="Top" Grid.Row="3"/>
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,10,0,0" VerticalAlignment="Top" Width="50" Height="50"  GrayLight="{Binding Detector.Reject.Reject1.IsActive, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Reject.Reject1.State, Converter={StaticResource InvertBool}}" RedLight="{Binding Detector.Reject.Reject1.State}"  Grid.Row="3"/>

                    <Label x:Name="Reject2Active_lbl" Content="{DynamicResource LabelReject2}" Margin="10,70,0,0"  HorizontalAlignment="Left" Width="148" Height="50" VerticalAlignment="Top" Grid.Row="3"/>
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,70,0,0" VerticalAlignment="Top" Width="50" Height="50"  GrayLight="{Binding Detector.Reject.Reject2.IsActive, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Reject.Reject2.State, Converter={StaticResource InvertBool}}" RedLight="{Binding Detector.Reject.Reject2.State}"  Grid.Row="3"/>

                    <Label x:Name="Reject3Active_lbl" Content="{DynamicResource LabelReject3}" Margin="10,130,0,0"  HorizontalAlignment="Left" Width="148" Height="50" VerticalAlignment="Top" Grid.Row="3" Grid.RowSpan="2"/>
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,130,0,0" VerticalAlignment="Top" Width="50" Height="50"  GrayLight="{Binding Detector.Reject.Reject3.IsActive, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Reject.Reject3.State, Converter={StaticResource InvertBool}}" RedLight="{Binding Detector.Reject.Reject3.State}"  Grid.Row="3" Grid.RowSpan="2"/>

                    <Label x:Name="Reject4Active_lbl" Content="{DynamicResource LabelReject4}" Margin="10,190,0,0"  HorizontalAlignment="Left" Width="148" Height="50" VerticalAlignment="Top" Grid.Row="3" Grid.RowSpan="2"/>
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,32,0,0" VerticalAlignment="Top" Width="50" Height="50"  GrayLight="{Binding Detector.Reject.Reject4.IsActive, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Reject.Reject4.State, Converter={StaticResource InvertBool}}" RedLight="{Binding Detector.Reject.Reject4.State}"  Grid.Row="4"/>

                    <Label x:Name="RejectAActive_lbl" Content="{DynamicResource LabelRejectA}" Margin="10,250,0,0"  HorizontalAlignment="Left" Width="148" Height="50" VerticalAlignment="Top" Grid.Row="3" Grid.RowSpan="2"/>
                    <cont:DiodeControl HorizontalAlignment="Left" Margin="125,92,0,0" VerticalAlignment="Top" Width="50" Height="50"  GrayLight="{Binding Detector.Reject.RejectA.IsActive, Converter={StaticResource InvertBool}}" GreenLight="{Binding Detector.Reject.RejectA.State, Converter={StaticResource InvertBool}}" RedLight="{Binding Detector.Reject.RejectA.State}"  Grid.Row="4"/>


                    <!--Buttons-->
                    <cont:PushButton Command="{Binding StatusViewModel.Command[OpenStatusWindow]}" Text="{DynamicResource ButtonStatusOpen}"  HorizontalAlignment="Left" Margin="10,0,0,0.5"  Grid.Row="6" VerticalAlignment="Bottom"  Width="120" Height="64"/>


                    <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1" HorizontalAlignment="Left">
                        <cont:ColorChangingButton Margin="20,0,0,0" Value="{Binding Detector.Settings.Zero}" Command="{Binding ServiceViewModel.Command[ToggleZero]}" TextON="{DynamicResource ButtonDisableZero}" TextOFF="{DynamicResource ButtonEnableZero}" IsEnabled="{Binding Detector.Settings.IsConnected}" Width="120" />
                        <cont:ColorChangingButton Margin="20,0,0,0" Value="{Binding Detector.Settings.AutoZero}" Command="{Binding ServiceViewModel.Command[ToggleAutozero]}" TextON="{DynamicResource ButtonDisableAutozero}" TextOFF="{DynamicResource ButtonEnableAutozero}" IsEnabled="{Binding Detector.Settings.IsConnected}" Width="120"/>
                        <cont:PushButton Margin="20,0,0,0" Command="{Binding ServiceViewModel.Command[Calibrate]}" Text="{DynamicResource ButtonCalibrate}" IsEnabled="{Binding Detector.Settings.IsConnected}" Width="120"/>
                        <cont:PushButton Margin="20,0,0,0" Command="{Binding MeasurementViewModel.Command[Zero]}" Text="{DynamicResource ButtonZero}" IsEnabled="{Binding Detector.Settings.IsConnected}" Width="120"/>
                    </StackPanel>


                    <!--Detector state buttons-->
                    <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right">
                        <cont:PushButton Command="{Binding MeasurementViewModel.Command[Test]}" IsEnabled="{Binding Detector.Settings.IsConnected}" Text="TEST" Margin="0,0,20,0" Width="120"/>
                        <cont:PushButton Command="{Binding MeasurementViewModel.Command[Vent]}" IsEnabled="{Binding Detector.Settings.IsConnected}" Text="VENT" Margin="0,0,20,0" Width="120"/>
                    </StackPanel>

                    <!--*****************************************************************************************************************************************-->

                    <Grid Grid.Column="1" Grid.RowSpan="6" Margin="0,0,0,6" VerticalAlignment="Stretch" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="600*"/>
                        </Grid.RowDefinitions>

                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="0" Height="30">

                            <cont:LabeledCheckbox Text="{DynamicResource LabelLeakrate}" IsChecked="{Binding Graph.LeakVisibility}" Foreground="Red" Margin="10,0,0,0"/>
                            <cont:LabeledCheckbox Text="{DynamicResource LabelTPpressure}" IsChecked="{Binding Graph.TPVisibility}" Foreground="Blue" Margin="10,0,0,0"/>
                            <cont:LabeledCheckbox Text="{Binding MeasurementViewModel.DisplayList[3]}" IsChecked="{Binding Graph.Analog1Visiblity}" Foreground="Purple" Margin="10,0,0,0"/>
                            <cont:LabeledCheckbox Text="{Binding MeasurementViewModel.DisplayList[4]}" IsChecked="{Binding Graph.Analog2Visiblity}" Foreground="Orange" Margin="10,0,0,0"/>
                            <cont:LabeledCheckbox Text="{Binding MeasurementViewModel.DisplayList[5]}" IsChecked="{Binding Graph.Analog3Visiblity}" Foreground="Salmon" Margin="10,0,0,0"/>
                            <cont:LabeledCheckbox Text="{Binding MeasurementViewModel.DisplayList[6]}" IsChecked="{Binding Graph.Analog4Visiblity}" Foreground="Green" Margin="10,0,0,0"/>

                        </StackPanel>

                        <oxy:Plot x:Name="Graph" IsLegendVisible="False"  Grid.Row="1" Margin="0,0,0,0" Width="auto" MinHeight="600" Background="Transparent" >

                            <oxy:Plot.Axes>
                                <oxy:DateTimeAxis Title="Time" StringFormat="HH:mm:ss" MajorGridlineStyle="Solid" MinorGridlineStyle="None" IntervalLength="30" Maximum="{Binding Graph.XaxisMax}" Minimum="{Binding Graph.XaxisMin}" />
                                <oxy:LogarithmicAxis Title="Leak rate [mbar/l.s]" AxisTitleDistance="15" IsZoomEnabled="False" TitleFontSize="14" MajorGridlineStyle="None" MinorGridlineStyle="None" TitleColor="Red" Minimum="1E-10" Maximum="1E-2" Key="Left" LabelFormatter="{Binding Graph.Formatter}" />
                                <oxy:LogarithmicAxis Title="Pressure [mbar]" TitleFontSize="14" TitleColor="Blue" Minimum="1E-4" Maximum="1E+4" Key="Right" Position="Right"  MajorGridlineStyle="Solid" MinorGridlineStyle="Solid" LabelFormatter="{Binding Graph.Formatter}" />
                            </oxy:Plot.Axes>

                            <oxy:LineSeries Title="Leak rate" YAxisKey="Left" Color="Red" StrokeThickness="2" Visibility="{Binding Graph.LeakVisibility, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Leakrate}"/>
                            <oxy:LineSeries Title="Test port pessure" YAxisKey="Right" Color="Blue" StrokeThickness="2" Visibility="{Binding Graph.TPVisibility, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Testpressure}"/>
                            <oxy:LineSeries Title="Analog 1" YAxisKey="Right" Color="Green" StrokeThickness="2" Visibility="{Binding Graph.Analog1Visiblity, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Analog1}"/>
                            <oxy:LineSeries Title="Analog 2" YAxisKey="Right" Color="Purple" StrokeThickness="2" Visibility="{Binding Graph.Analog2Visiblity, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Analog2}"/>
                            <oxy:LineSeries Title="Analog 3" YAxisKey="Right" Color="Yellow" StrokeThickness="2" Visibility="{Binding Graph.Analog3Visiblity, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Analog3}"/>
                            <oxy:LineSeries Title="Analog 4" YAxisKey="Right" Color="Orange" StrokeThickness="2" Visibility="{Binding Graph.Analog4Visiblity, Converter={StaticResource BoolToVisibility}}" ItemsSource="{Binding Graph.Analog4}"/>

                        </oxy:Plot>
                    </Grid>

                    <Label x:Name="DetectorMode_lbl" Content="{DynamicResource LabelDetectorMode}" Style="{StaticResource CenteredLabel}" Margin="10,18.5,10,0" VerticalAlignment="Top" Height="32" Grid.Row="1" />
                    <TextBox x:Name="CurrentMode_txt_Copy" Style="{StaticResource TextboxROstyle}"  Margin="12,50.5,10,0" Text="{Binding Detector.Settings.DetectorMode, UpdateSourceTrigger=PropertyChanged}" Height="44" VerticalAlignment="Top" Grid.Row="1"/>
                    <Image Grid.Column="2" Source="Resources/Images/logo.png" HorizontalAlignment="Left" Height="61" Margin="150,0,0,1.5" Grid.Row="6" VerticalAlignment="Bottom" Width="90"/>

                </Grid>
            </TabItem>

            <!--*****************************************************************************************************************************************-->
            <!--*****************************************************************     SERVICE     *******************************************************-->
            <!--*****************************************************************************************************************************************-->

            <!--#region Service-->
            <TabItem x:Name="SERVIS" Header="{DynamicResource HeaderService}" Width="170" Height="50"  Margin="14,5,-14,-2.5" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="320" />
                        <ColumnDefinition Width="600" />
                        <ColumnDefinition Width="380" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="310"/>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="349"/>
                    </Grid.RowDefinitions>

                    <!--************** TURBO ***************-->
                    <!--#region Turbo pump-->
                    <!--Turbo backgroud-->
                    <cont:BackgroudBox Header="{DynamicResource LabelTurboPump}" HeaderHeight="50" HeaderPosition="Center" Margin="2" Grid.RowSpan="2"/>

                    <!--Turbo text blocks-->
                    <StackPanel Orientation="Vertical" Margin="10,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" >
                        <cont:LabeledTextbox x:Name="TurboMode" Text="{DynamicResource LabelTurboMode}" Value="{Binding Detector.Turbo.TurboMode, UpdateSourceTrigger=PropertyChanged}" TextboxReadonly="True" TextboxWidth="120" Margin="0,0,0,5" Width="300"/>
                        <cont:LabeledTextbox x:Name="TurboFault" Text="{DynamicResource LabelTurboStatus}" Value="{Binding Detector.Turbo.TurboFault, UpdateSourceTrigger=PropertyChanged}" TextboxReadonly="True" TextboxWidth="120" Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="TurboSpeed" Text="{DynamicResource LabelTurboSpeed}" Value="{Binding Detector.Turbo.TurboSpeed, UpdateSourceTrigger=PropertyChanged}" TextboxReadonly="True" TextboxWidth="120"  Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="TurboTemp" Text="{DynamicResource LabelTurboTemperature}" Value="{Binding Detector.Turbo.TurboTemp, UpdateSourceTrigger=PropertyChanged}" TextboxReadonly="True" TextboxWidth="120" Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="TurboHours" Text="{DynamicResource LabelTurboOperatingHours}" Value="{Binding Detector.Turbo.TurboHours, UpdateSourceTrigger=PropertyChanged}" TextboxReadonly="True" TextboxWidth="120"/>
                    </StackPanel>
                    <!--Turbo buttons-->
                    <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleSoftStart]}" TextON="{DynamicResource ButtonDisableSoftstart}" TextOFF="{DynamicResource ButtonEnableSoftstart}" Value="{Binding Detector.Turbo.SoftStart}" HorizontalAlignment="Right" Focusable="False" Margin="0,285,191,0" Width="120" Height="60" VerticalAlignment="Top" Grid.RowSpan="2"/>
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[ResetTurbo]}" Text="{DynamicResource ButtonResetTurbo}" Margin="191,285,0,0" Focusable="False"  Height="60" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" Grid.RowSpan="2"/>
                    <!--#endregion-->



                    <!--************* IONCHAMEBR ***********-->
                    <!--#region Ion chamber -->
                    <!--Ion chamber background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelIonChamber}" HeaderHeight="50" HeaderPosition="Center" Grid.Column="1"  Margin="2"/>

                    <!--Ion chamber text boxes-->
                    <StackPanel Orientation="Horizontal" Grid.Column="1" Margin="10,60,0,0">
                        <StackPanel Orientation="Vertical"  VerticalAlignment="Top" HorizontalAlignment="Left" >
                            <cont:LabeledTextbox x:Name="IonChamber" Text="{DynamicResource LabelVolatage}" Value="{Binding Detector.Ionchamber.Voltage}" TextboxReadonly="True" Height="40" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Emision" Text="{DynamicResource LabelEmission}" Value="{Binding Detector.Ionchamber.Emission}" TextboxReadonly="True" Height="40"  Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Gain" Text="{DynamicResource LabelGain}" Value="{Binding Detector.Ionchamber.Gain}" TextboxReadonly="True" Height="40" Margin="0,0,0,5" />
                            <cont:LabeledTextbox x:Name="Offset1" Text="{DynamicResource LabelOffset1}" Value="{Binding Detector.Ionchamber.Offset1}" TextboxReadonly="True" Height="40" Margin="0,0,0,5"/>
                        </StackPanel>

                        <StackPanel Orientation="Vertical" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="15,0,0,0" >
                            <cont:LabeledTextbox x:Name="Fil1Hours" Text="{DynamicResource LabelFilamet1Hours}"  Value="{Binding Detector.Ionchamber.FilHours1}" TextboxReadonly="True" Height="40" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Fil2Hours" Text="{DynamicResource LabelFilamet2Hours}" Value="{Binding Detector.Ionchamber.FilHours2}" TextboxReadonly="True" Height="40" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="FilamentStatus" Text="{DynamicResource LabelFilametStatus}" Value="{Binding Detector.Ionchamber.FilStatus}" TextboxReadonly="True" Height="40" Margin="0,20,0,0"/>

                        </StackPanel>
                    </StackPanel>


                    <!--Ion chamber buttons-->
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[Tune]}" Text="{DynamicResource ButtonTune}" Margin="10,0,0,7"  Grid.Column="1" HorizontalAlignment="Left" Width="100" Height="50" VerticalAlignment="Bottom"/>
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[ResetFilament1]}" Text="{DynamicResource ButtonResetFilament}" Margin="498,0,0,210" Focusable="False"  Grid.Column="1" Height="40" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="98"/>
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[ResetFilament2]}" Text="{DynamicResource ButtonResetFilament}" Margin="498,0,0,165" Focusable="False"  Grid.Column="1" HorizontalAlignment="Left" Width="98" Height="40" VerticalAlignment="Bottom"/>
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleFilament]}" Text="{DynamicResource ButtonSwitchFilaments}" Margin="0,0,10,7"  Grid.Column="1" HorizontalAlignment="Right" Width="138" Height="50" VerticalAlignment="Bottom"/>

                    <!--#endregion-->



                    <!--************** REJECT ***********-->
                    <!--#region Rejects-->
                    <!--Reject background-->

                    <cont:BackgroudBox Header="{DynamicResource LabelRejectSetpoints}" HeaderHeight="50" HeaderPosition="Center" Grid.Column="2" MinWidth="280" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="2" />

                    <!--Reject text boxes-->
                    <StackPanel Orientation="Horizontal" Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Left"  Margin="10,60,0,0">
                        <StackPanel Orientation="Vertical" >
                            <cont:LabeledTextbox x:Name="Reject1" Text="{DynamicResource LabelReject1}" Value="{Binding Detector.Reject.Reject1.Value}" Command="{Binding ServiceViewModel.Command[SetReject]}" CommandPar="1"  Height="40" Width="200" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Reject2" Text="{DynamicResource LabelReject2}" Value="{Binding Detector.Reject.Reject2.Value}" Height="40" Width="200" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Reject3" Text="{DynamicResource LabelReject3}" Value="{Binding Detector.Reject.Reject3.Value}" Height="40" Width="200" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="Reject4" Text="{DynamicResource LabelReject4}" Value="{Binding Detector.Reject.Reject4.Value}" Height="40" Width="200" Margin="0,0,0,5"/>
                            <cont:LabeledTextbox x:Name="RejectA" Text="{DynamicResource LabelRejectA}" Value="{Binding Detector.Reject.RejectA.Value}" Height="40" Width="200" Margin="0,0,0,5"/>
                        </StackPanel>


                        <!--Reject High-Low buttons-->
                        <StackPanel Orientation="Vertical">
                            <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRejectOnOff]}" CommandPar="1" TextON="{DynamicResource ButtonRejectOff}" TextOFF="{DynamicResource ButtonRejectOn}" Value="{Binding Detector.Reject.Reject1.State}" Width="61" Height="40" Margin="10,0,0,5"/>
                            <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRejectOnOff]}" CommandPar="2" TextON="{DynamicResource ButtonRejectOff}" TextOFF="{DynamicResource ButtonRejectOn}" Value="{Binding Detector.Reject.Reject2.State}" Width="61" Height="40" Margin="10,0,0,5"/>
                            <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRejectOnOff]}" CommandPar="3" TextON="{DynamicResource ButtonRejectOff}" TextOFF="{DynamicResource ButtonRejectOn}" Value="{Binding Detector.Reject.Reject3.State}" Width="61" Height="40" Margin="10,0,0,5"/>
                            <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRejectOnOff]}" CommandPar="4" TextON="{DynamicResource ButtonRejectOff}" TextOFF="{DynamicResource ButtonRejectOn}" Value="{Binding Detector.Reject.Reject4.State}" Width="61" Height="40" Margin="10,0,0,5"/>
                            <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRejectOnOff]}" CommandPar="A" TextON="{DynamicResource ButtonRejectOff}" TextOFF="{DynamicResource ButtonRejectOn}" Value="{Binding Detector.Reject.RejectA.State}" Width="61" Height="40" Margin="10,0,0,5"/>

                        </StackPanel>
                        <!--Reject on-off buttons-->
                        <StackPanel Orientation="Vertical">
                            <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleRejectHighLow]}" CommandPar="1" Text="{DynamicResource ButtonRejectHigh}" Width="80" Height="40" Margin="10,0,0,5"/>
                            <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleRejectHighLow]}" CommandPar="2" Text="{DynamicResource ButtonRejectHigh}" Width="80" Height="40" Margin="10,0,0,5"/>
                            <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleRejectHighLow]}" CommandPar="3" Text="{DynamicResource ButtonRejectHigh}" Width="80" Height="40" Margin="10,0,0,5"/>
                            <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleRejectHighLow]}" CommandPar="4" Text="{DynamicResource ButtonRejectHigh}" Width="80" Height="40" Margin="10,0,0,5"/>
                            <cont:PushButton Command="{Binding ServiceViewModel.Command[ToggleRejectHighLow]}" CommandPar="A" Text="{DynamicResource ButtonRejectHigh}" Width="80" Height="40" Margin="10,0,0,5"/>
                        </StackPanel>
                    </StackPanel>
                    <!--#endregion-->



                    <!--*****************************************************************************************************************************************-->
                    <!--*****************************************************************     SETTINGS    *******************************************************-->
                    <!--*****************************************************************************************************************************************-->


                    <!--********** DETECTOR SETTINGS ************-->
                    <!--#region  Detector settings-->
                    <!--Detector settings background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelDetectorSettings}" HeaderHeight="50" HeaderPosition="Center" Grid.Row="2" Margin="2,2,2,96"/>

                    <!--Detector setting buttons-->
                    <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleAutozero]}" TextON="{DynamicResource ButtonDisableAutozero}" TextOFF="{DynamicResource ButtonEnableAutozero}" Value="{Binding Detector.Settings.AutoZero}" Focusable="False"  Margin="10,61,0,0" Width="120"  Grid.Row="2" Height="60" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                    <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleZero]}" TextON="{DynamicResource ButtonDisableZero}" TextOFF="{DynamicResource ButtonEnableZero}" Value="{Binding Detector.Settings.Zero}" Focusable="False" Margin="0,61,10,0" Width="120"  Grid.Row="2" Height="60" VerticalAlignment="Top" HorizontalAlignment="Right"/>
                    <cont:LabeledCombobox x:Name="PreheatTime" Margin="9,139,11,170" ComboWidth="120" Text="{DynamicResource LabelPreheatTime}" ItemsSource="{Binding Detector.Settings.PreheatTimes}" SelectedIndex="{Binding Detector.Settings.PreaheatSelection}"  Height="40" Grid.Row="2"/>

                    <!--#endregion-->



                    <!--*********** CALIBRATION SETTINGS ************-->
                    <!--#region Calibration-->
                    <!--Calibration background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelDetectorCalibartion}" HeaderHeight="50" HeaderPosition="Center" Grid.Row="1" Grid.RowSpan="2" Grid.Column="1" Margin="2,2,2,96"/>

                    <!--Calibration text boxes-->
                    <StackPanel Orientation="Vertical" Grid.Row="1" Grid.RowSpan="2" Grid.Column="1" Margin="10,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left">
                        <cont:LabeledTextbox x:Name="InternalLeak" Text="{DynamicResource LabelInternalLeak}" Value="{Binding Detector.Calibration.InternalLeak}" Height="40" Width="300" Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="InternalTemp" Text="{DynamicResource LabelLeakTemperature}" Value="{Binding Detector.Calibration.InternalTemp}" TextboxReadonly="True" Height="40" Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="InternalFact" Text="{DynamicResource LabelTemperatureFactor}" Value="{Binding Detector.Calibration.InternalFactor}" TextboxReadonly="True" Height="40"  Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="InternalExp"  Text="{DynamicResource LabelExpirationDate}" Value="{Binding Detector.Calibration.InternalExpire}" Height="40" Margin="0,0,0,5" />

                    </StackPanel>

                    <cont:LabeledTextbox x:Name="LastCalibration" Text="{DynamicResource LabelLastCalibration}" Value="{Binding Detector.Calibration.LastCal}" TextboxReadonly="True" Height="40" Margin="331,93,10,216" Grid.Column="1" Grid.Row="2"/>

                    <cont:LabeledTextbox x:Name="ExternalLeak" Text="{DynamicResource LabelExternalLeak}" Value="{Binding Detector.Calibration.ExternalLeak}" Height="40" Margin="331,10,10,0" Grid.Column="1" Grid.Row="2" VerticalAlignment="Top"/>


                    <!--#endregion-->



                    <!--************ RANGE ***********-->
                    <!--#region Range-->
                    <!--#endregion-->

                    <!--Calibration comboboxes-->
                    <cont:LabeledCombobox x:Name="CalibrationType" Margin="0,204,291,0" Text="{DynamicResource LabelCalibrationType}" ItemsSource="{Binding ServiceViewModel.CalibrationTypes}" SelectedIndex="{Binding Detector.Calibration.CalibrationSelection}" Command="{Binding ServiceViewModel.Command[ChangeCalibrationType]}" Grid.Column="1" Height="40" HorizontalAlignment="Right" Width="297" Grid.Row="2" VerticalAlignment="Top"/>

                    <!--Calibration buttons-->
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[Calibrate]}" Text="{DynamicResource ButtonCalibrate}" Margin="0,184,150,0" Grid.Column="1" HorizontalAlignment="Right" Width="120" Height="60" VerticalAlignment="Top" Grid.Row="2"/>
                    <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleSplitflow]}" TextON="{DynamicResource ButtonDisableSplitflow}" TextOFF="{DynamicResource ButtonEnableSplitflow}"  Value="{Binding Detector.Calibration.Splitflow}"  Focusable="False" Margin="0,184,10,0" VerticalAlignment="Top" Height="60" Grid.Column="1" HorizontalAlignment="Right" Width="120" Grid.Row="2"/>

                    <!--Range background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelRanges}" HeaderHeight="50" HeaderPosition="Center" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Margin="2,2,2,96"/>

                    <!--Range textboxes-->
                    <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Margin="10,60,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                        <cont:LabeledTextbox x:Name="Exponent" Text="{DynamicResource LabelManualRange}" Value="{Binding Detector.Range.Exponent}" Height="40" Margin="0,0,0,5" Width="360"/>
                        <cont:LabeledTextbox x:Name="Range"  Text="{DynamicResource LabelLeastRange}" Value="{Binding Detector.Range.RangeValue}" Height="40" Margin="0,0,0,5"/>
                        <cont:LabeledTextbox x:Name="RangeStop" Text="{DynamicResource LabelRangestop}" Value="{Binding Detector.Range.RangeStop}" Height="40" Margin="0,0,0,5"/>

                    </StackPanel>

                    <!--Range buttons-->
                    <cont:ColorChangingButton Command="{Binding ServiceViewModel.Command[ToggleRangestop]}" TextON="{DynamicResource ButtonDisableRangestop}" TextOFF="{DynamicResource ButtonEnableRangestop}" Value="{Binding Detector.Range.RangestopActive}" HorizontalAlignment="Left" Focusable="False" Margin="251,0,0,105" Width="120"  Grid.Column="2" Grid.Row="2" Height="60" VerticalAlignment="Bottom"/>
                    <cont:PushButton Command="{Binding ServiceViewModel.Command[AutoRange]}" Text="{DynamicResource ButtonAutorange}" Grid.Column="2" Grid.Row="2" Width="120" HorizontalAlignment="Left" Margin="10,0,0,105" Height="60" VerticalAlignment="Bottom"/>

                </Grid>
            </TabItem>
            <!--#region  Settings-->
            <TabItem x:Name="SETTINGS" Header="{DynamicResource HeaderSettings}" Width="170" Height="50"  Margin="16,5,-16,-2.5" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="320"/>
                        <ColumnDefinition Width="400"/>
                        <ColumnDefinition Width="610*"/>

                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="370"/>
                        <RowDefinition Height="120"/>
                        <RowDefinition Height="408*"/>
                    </Grid.RowDefinitions>


                    <!--************** Detector settings ***************-->
                    <!--#region Serial settings-->

                    <!--Connection settings background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelDetectorSerialSettings}" HeaderHeight="50" HeaderPosition="Center"  Margin="2"/>


                    <!--#endregion-->



                    <!--******************************* Language settings ***************************************-->
                    <!--#region  Language settings -->
                    <!--#endregion-->



                    <!--******************************* Turck settings ***************************************-->

                    <!--#region  Turck settings-->
                    <!--Detector settings comboboxes-->
                    <cont:LabeledCombobox x:Name="DetectorType" Margin="10,65,10,265" ComboWidth="120" SelectedIndex="{Binding SettingViewModel.DetectorIndex}" Text="{DynamicResource LabelDetectorType}" ItemsSource="{Binding SettingViewModel.DetectorTypes}" />
                    <cont:LabeledCombobox x:Name="COMport" Margin="10,116,10,214" ComboWidth="120" Text="{DynamicResource LabelDetectorPort}"  ItemsSource="{Binding SettingViewModel.SerialPorts}" SelectedIndex="{Binding SettingViewModel.PortIndex}" />

                    <!--Detector settings buttons-->
                    <cont:PushButton Command="{Binding SettingViewModel.Command[Autodetect]}" Text="{DynamicResource ButtonAutodetect}" Margin="10,0,0,10"  HorizontalAlignment="Left" Width="140" Height="60" VerticalAlignment="Bottom" />
                    <cont:ColorChangingButton Command="{Binding SettingViewModel.Command[ConnectDetector]}" TextON="{DynamicResource ButtonDisconnect}" TextOFF="{DynamicResource ButtonConnect}" Value="{Binding Detector.Settings.IsConnected}"  Margin="0,0,10,10"  HorizontalAlignment="Right" Width="140" Height="60" VerticalAlignment="Bottom"/>
                    <!--Language setting combobox-->
                    <cont:LabeledCombobox  Margin="10,0,0,10" Command="{Binding SettingViewModel.Command[LanguageChanged]}" SelectedIndex="{Binding SettingViewModel.LanguageIndex}" Text="{DynamicResource LabelLanguage}"  ItemsSource="{Binding SettingViewModel.Languages}" VerticalAlignment="Bottom" Height="40" HorizontalAlignment="Left" Width="220" ComboWidth="120" Grid.Row="3" />
                    <!--Turck settings background-->
                    <cont:BackgroudBox Header="{DynamicResource LabelControlSettings}" HeaderHeight="50" HeaderPosition="Center" Grid.Column="1" Margin="2"/>


                    <!--Turck settings combobox-->
                    <cont:LabeledCombobox x:Name="ControlType" Margin="10,65,10,265" ComboWidth="180" SelectedIndex="{Binding SettingViewModel.ControlIndex}" Text="{DynamicResource LabelControlType}" ItemsSource="{Binding SettingViewModel.ControlModules}" Grid.Column="1" />

                    <!--Turck setting text boxes-->
                    <cont:LabeledTextbox x:Name="ControlIP" Text="{DynamicResource LabelControlIP}" Value="{Binding SettingViewModel.IPAddress, UpdateSourceTrigger=PropertyChanged}" TextboxWidth="180" Height="40" Margin="10,116,10,0" VerticalAlignment="Top" Width="auto" Grid.Column="1" />
                    <cont:LabeledTextbox x:Name="ControlMAC" Text="{DynamicResource LabelControlMAC}" Value="{Binding SettingViewModel.MACAddress, UpdateSourceTrigger=PropertyChanged}" TextboxWidth="180" Height="40" Margin="10,161,10,0" VerticalAlignment="Top" Width="auto" Grid.Column="1" />

                    <!--Truck settings checkboxes-->
                    <cont:LabeledCheckbox Text="{DynamicResource LabelControlUsingIP}" Command="{Binding SettingViewModel.Command[IPUsingChanged]}" Grid.Column="1"  VerticalContentAlignment="Center" IsChecked="{Binding SettingViewModel.UsingIP, Mode=TwoWay}" Margin="10,210,10,120"/>

                    <cont:LabeledCheckbox Text="{DynamicResource LabelControlUsingMAC}"  Command="{Binding SettingViewModel.Command[MACUsingChanged]}"  Grid.Column="1"  VerticalContentAlignment="Center" IsChecked="{Binding SettingViewModel.UsingMAC, Mode=TwoWay}" Margin="10,255,10,75"/>

                    <!--Turck settings buttons-->
                    <cont:ColorChangingButton Command="{Binding SettingViewModel.Command[ConnectControl]}" TextON="{DynamicResource ButtonDisconnect}" TextOFF="{DynamicResource ButtonConnect}" Value="{Binding ControlModule.IsConnected}" Margin="0,0,10,10" HorizontalAlignment="Right" Width="140" Grid.Column="1" Height="60" VerticalAlignment="Bottom"/>
                    <!--#endregion-->

                    <cont:BackgroudBox Header="{DynamicResource LabelControlSettings}" HeaderHeight="50" HeaderPosition="Center" Grid.Column="2" Grid.RowSpan="2" Margin="2"/>
                    <StackPanel Orientation="Vertical" Grid.Column="2" Margin="10,50,0,0" Grid.RowSpan="2">

                        <CustomControls:AnalogControl AnalogName="{Binding MeasurementViewModel.DisplayList[3], Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SensorTypes="{Binding SettingViewModel.AnalogConvertions}" InputValue="{Binding ControlModule.AnalogValues[0]}" Result="{Binding ControlModule.Analogs[Analog1].Result}" Width="620" HorizontalAlignment="Left"/>
                        <CustomControls:AnalogControl AnalogName="{Binding MeasurementViewModel.DisplayList[4], Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SensorTypes="{Binding SettingViewModel.AnalogConvertions}" InputValue="{Binding ControlModule.AnalogValues[1]}" Result="{Binding ControlModule.Analogs[Analog2].Result}" Width="620" HorizontalAlignment="Left"/>
                        <CustomControls:AnalogControl AnalogName="{Binding MeasurementViewModel.DisplayList[5], Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SensorTypes="{Binding SettingViewModel.AnalogConvertions}" InputValue="{Binding ControlModule.AnalogValues[2]}" Result="{Binding ControlModule.Analogs[Analog3].Result}" Width="620" HorizontalAlignment="Left"/>
                        <CustomControls:AnalogControl AnalogName="{Binding MeasurementViewModel.DisplayList[6], Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SensorTypes="{Binding SettingViewModel.AnalogConvertions}" InputValue="{Binding ControlModule.AnalogValues[3]}" Result="{Binding ControlModule.Analogs[Analog4].Result}" Width="620" HorizontalAlignment="Left"/>

                    </StackPanel>


                </Grid>
            </TabItem>


            <!--*****************************************************************************************************************************************-->
            <!--*****************************************************************     PARAMETERS  *******************************************************-->
            <!--*****************************************************************************************************************************************-->



            <!--#region Parameters-->
            <TabItem x:Name="PARAMETERS" Header="{DynamicResource HeaderParameters}" Width="170" Height="50" Margin="18,5,-18,-2.5" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1000*"/>
                        <ColumnDefinition Width="270"/>
                    </Grid.ColumnDefinitions>


                    <!--Parameter Datagrid -->
                    <DataGrid x:Name="ParameterGrid" CanUserAddRows="False" SelectionMode="Single" Background="White" ItemsSource="{Binding ParameterViewModel.Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                              AutoGenerateColumns="False" RowHeight="40" SelectedItem="{Binding ParameterViewModel.SelectedParameter}" HeadersVisibility="Column" VerticalContentAlignment="Center" Margin="10"
                              HorizontalContentAlignment="Left" >
                        <DataGrid.Resources>
                            <Style TargetType="{x:Type DataGridCell}">
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Background" Value="Azure" />
                                        <Setter Property="Foreground" Value="Black"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.Resources>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <i:InvokeCommandAction Command="{Binding ParameterViewModel.Command[SelectionChanged]}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="{DynamicResource LabelParameterName}" ElementStyle="{StaticResource DataCellStyleCenter}" Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged}" CanUserResize="true"  />
                            <DataGridTextColumn Header="{DynamicResource LabelParameterRequired}" ElementStyle="{StaticResource DataCellStyleCenter}" Binding="{Binding RequiredValue, UpdateSourceTrigger=PropertyChanged}" CanUserResize="true"/>
                            <DataGridTextColumn Header="{DynamicResource LabelActualValue}" ElementStyle="{StaticResource DataCellStyleCenter}" Binding="{Binding ActualValue, UpdateSourceTrigger=PropertyChanged}" CanUserResize="True"/>
                            <DataGridTextColumn Header="{DynamicResource LabelDescription}" ElementStyle="{StaticResource DataCellStyleLeft}" Binding="{Binding Description, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
                        </DataGrid.Columns>
                        <DataGrid.ColumnHeaderStyle>
                            <Style TargetType="{x:Type DataGridColumnHeader}">
                                <Setter Property="Padding" Value="5"/>
                                <Setter Property="Background" Value="LightGray" />
                                <Setter Property="BorderBrush" Value="Black" />
                                <Setter Property="BorderThickness" Value="1" />
                            </Style>
                        </DataGrid.ColumnHeaderStyle>
                    </DataGrid>

                    <!-- Paraemter buttons-->
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[ChangeRequiredValue]}" Text="{DynamicResource ButtonChangeValue}" Margin="10,262,10,0"  Grid.Column="1" Height="60" VerticalAlignment="Top" />
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[SendToHLD]}" Text="{DynamicResource ButtonSendToHLD}" Margin="10,0,10,79"  Grid.Column="1" Height="50" VerticalAlignment="Bottom" />
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[ExportValues]}" Text="{DynamicResource ButtonExportValues}" Margin="10,0,0,10"  Grid.Column="1" Height="55" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="110"  />
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[ImportValues]}" Text="{DynamicResource ButtonImportValues}" Margin="0,0,10,10"  Grid.Column="1" Height="55" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="110" />


                    <!--Parameter Labels-->
                    <Label x:Name="SelectedItemName_lbl" Content="{DynamicResource LabelSelectedParameter}" Style="{StaticResource CenteredLabel}" Grid.Column="2"  Height="40" VerticalAlignment="Top"/>
                    <Label x:Name="SelectedParameterValue_lbl" Content="{DynamicResource LabelParameterValue}" Style="{StaticResource CenteredLabel}" Grid.Column="1"  Height="45" VerticalAlignment="Top" Margin="0,85,0,0"/>
                    <Label x:Name="NewParameterValue_lbl" Content="{DynamicResource LabelParameterRequired}" Style="{StaticResource CenteredLabel}" Grid.Column="2" Margin="0,174,0,0" Height="38" VerticalAlignment="Top"/>

                    <!--Parameter Text boxes -->
                    <TextBox x:Name="SelectedItemName_txt" Text="{Binding SelectedItem.Name, ElementName=ParameterGrid}" TextWrapping="Wrap" Style="{StaticResource TextboxROstyle}" Grid.Column="2" Margin="10,39,10,0" Height="45" VerticalAlignment="Top"/>
                    <TextBox x:Name="SelectedParameterValue_txt" Text="{Binding SelectedItem.ActualValue, ElementName=ParameterGrid}" TextWrapping="Wrap" Style="{StaticResource TextboxROstyle}"  Grid.Column="2" Margin="10,130,10,0" Height="45" VerticalAlignment="Top"/>
                    <TextBox x:Name="NewParameterValue_txt" Text="{Binding ParameterViewModel.RequiredValue, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Grid.Column="2" Margin="10,212,10,0" Height="45" VerticalAlignment="Top"/>

                    <!--Parameter Numpad-->
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="1" Text="1" Margin="10,335,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="2"  Text="2" Margin="95,335,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="3"  Text="3" Margin="180,335,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>

                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="4"  Text="4" Margin="10,390,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="5"  Text="5" Margin="95,390,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="6"  Text="6" Margin="180,390,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>

                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="7"  Text="7" Margin="10,445,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="8"  Text="8" Margin="95,445,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="9"  Text="9" Margin="180,445,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="."  Text="." Margin="10,500,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="0"  Text="0" Margin="95,500,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>
                    <cont:PushButton Command="{Binding ParameterViewModel.Command[NumpadClick]}" CommandPar="C"  Text="C" Margin="180,500,0,0"  Grid.Column="1" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80"/>


                </Grid>
            </TabItem>



            <!--*****************************************************************************************************************************************-->
            <!--*****************************************************************     TERMINAL   ********************************************************-->
            <!--*****************************************************************************************************************************************-->

            <!--#region Terminal-->
            <TabItem x:Name="TERMINAL" Header="{DynamicResource HeaderTerminal}" Width="170" Height="50"  Margin="20,5,-20,-2.5" >

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="180"/>
                        <RowDefinition Height="350*"/>
                        <RowDefinition Height="200"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="800*"/>
                        <ColumnDefinition Width="520"/>
                    </Grid.ColumnDefinitions>

                    <!-- Terminal console-->
                    <Label x:Name="CommandConsole_lbl" Content="{DynamicResource LabelCommandConsole}" Margin="10,10,130,0" Grid.Column="1" Height="41" VerticalAlignment="Top"/>
                    <TextBox x:Name="SendData_txt" Text="{Binding TerminalViewModel.ConsoleContent, UpdateSourceTrigger=PropertyChanged}"  VerticalContentAlignment="Center" TextWrapping="Wrap" TextAlignment="Left" Margin="10,50,0,0" Height="41" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Left" Width="380"/>

                    <!--Terminal Informationbox-->
                    <TextBox x:Name="CommandInfo_txt" Style="{StaticResource TextboxROstyle}" Grid.Column="1" Margin="10,35,10,60" TextWrapping="Wrap" Text="{Binding TerminalViewModel.SelectionInfo}" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" Grid.Row="2"/>
                    <Label x:Name="CommandInfo_lbl" Content="{DynamicResource LabelInformation}" Margin="10,1,0,0" Grid.Column="1" HorizontalAlignment="Left" Width="498" Grid.Row="2" Height="34" VerticalAlignment="Top"/>

                    <!--Terminal buttons-->
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[SendCommand]}" Text="{DynamicResource ButtonSend}" Margin="418,50,0,0" Grid.Column="1" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" Width="90"  />
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[Service1]}" Text="SERVICE 1" Margin="10,100,0,0" Grid.Column="1" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" />
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[Service2]}" Text="SERVICE 2" Margin="170,100,0,0" Grid.Column="1" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" />
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[CopyToConsole]}" Text="{DynamicResource ButtonCopySelection}" Grid.Column="2" Margin="65,0,65,6"   Height="60" Width="240" VerticalAlignment="Bottom" Grid.Row="1" />
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[ClearTerminal]}" Text="{DynamicResource ButtonClear}" Margin="10,0,0,10.2" Grid.Column="2" HorizontalAlignment="Left" Width="90" Height="40" VerticalAlignment="Bottom" Grid.Row="3" />
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[SaveTerminal]}" Text="{DynamicResource ButtonSave}" Margin="110,0,0,10" Grid.Column="2" HorizontalAlignment="Left" Width="90" Height="40" VerticalAlignment="Bottom" Grid.Row="3"/>
                    <cont:PushButton Command="{Binding TerminalViewModel.Command[OpenManual]}" Text="{DynamicResource ButtonOpenManual}" HorizontalAlignment="Right" Margin="0,0,10,10" Panel.ZIndex="1" VerticalAlignment="Bottom" Width="170" Height="40" Grid.Row="2" Grid.Column="1"/>

                    <!--Terminal command list-->
                    <Label x:Name="AvailibleCommands_lbl" Content="{DynamicResource LabelListCommands}" Margin="10,0,270,0" Grid.Column="2" Height="38" VerticalAlignment="Bottom"/>
                    <ListBox x:Name="AvailibleCommands_lbox" ItemsSource="{Binding Detector.Communication.CommunicationList.Commands}" SelectedItem="{Binding TerminalViewModel.SelectedCommand}" SelectedIndex="{Binding TerminalViewModel.SelectedCommandIndex}" Grid.Column="2" Margin="10,0,270,75" Grid.Row="1">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[CopyCommand]}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="SelectionChanged">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[CommandChanged]}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="LostFocus">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[LostFocusCommand]}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>

                    <!--Terminal enquiry list-->
                    <Label x:Name="AvailibleEnquires_lbl" Content="{DynamicResource LabelListEnquires}" Margin="0,0,10,0" Grid.Column="2" HorizontalAlignment="Right" Width="240" Height="38" VerticalAlignment="Bottom"/>
                    <ListBox x:Name="AvailibleEnquires_lbox" ItemsSource="{Binding Detector.Communication.CommunicationList.Enquires}" SelectedItem="{Binding TerminalViewModel.SelectedEnquiry}" SelectedIndex="{Binding TerminalViewModel.SelectedEnquiryIndex}" Grid.Column="2" Margin="270,0,10,75" Grid.Row="1">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[CopyEnquiry]}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="SelectionChanged">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[EnquiryChanged]}"/>
                            </i:EventTrigger>
                            <i:EventTrigger EventName="LostFocus">
                                <i:InvokeCommandAction Command="{Binding TerminalViewModel.Command[LostFocusEnquiry]}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>

                    <!--Terminal log-->
                    <ListBox ItemsSource="{Binding TerminalViewModel.TerminalLog, UpdateSourceTrigger=PropertyChanged}" AlternationCount="2" Margin="5" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.RowSpan="3">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel.Resources>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="Margin" Value="10,10,0,0"/>
                                        </Style>
                                    </StackPanel.Resources>
                                    <TextBlock Text="{Binding Date}" FontWeight="Bold" />
                                    <TextBlock Text="{Binding Time}"/>
                                    <TextBlock Text="{Binding Text}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                </Grid>
            </TabItem>
        </TabControl>



        <!--*****************************************************************************************************************************************-->
        <!--*****************************************************************     SHARED BUTTONS   **************************************************-->
        <!--*****************************************************************************************************************************************-->


        <Button x:Name="EXIT" Content="EXIT" Command="{Binding WindowCommands[Exit]}" Background="Red" VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Margin="0,5,10,0" Width="45">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid RenderTransformOrigin="0.5,0.5" x:Name="RootGrid">
                        <Border  CornerRadius="7">
                            <Border.Background>
                                <ImageBrush ImageSource="Resources/Images/exit_v2.png" />
                            </Border.Background>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property ="IsPressed"  Value ="True">
                            <Setter TargetName ="RootGrid"  Property="RenderTransform">
                                <Setter.Value>
                                    <ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>



        <Button x:Name="Maximize_btn" Command="{Binding WindowCommands[Resize]}"  VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Width="45" Margin="0,5,60,0">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid RenderTransformOrigin="0.5,0.5" x:Name="RootGrid">
                        <Border  CornerRadius="7">
                            <Border.Background>
                                <ImageBrush ImageSource="Resources/Images/resize_v2.png" />
                            </Border.Background>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property ="IsPressed"  Value ="True">
                            <Setter TargetName ="RootGrid"  Property="RenderTransform">
                                <Setter.Value>
                                    <ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>


        <Button x:Name="Minimize_btn" Command="{Binding WindowCommands[Minimize]}"  Content="_" VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Width="45" Margin="0,5,110,0">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid RenderTransformOrigin="0.5,0.5" x:Name="RootGrid">
                        <Border  CornerRadius="7">
                            <Border.Background>
                                <ImageBrush ImageSource="Resources/Images/minimize_v2.png" />
                            </Border.Background>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property ="IsPressed"  Value ="True">
                            <Setter TargetName ="RootGrid"  Property="RenderTransform">
                                <Setter.Value>
                                    <ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>


    </Grid>
</Window>
