<UserControl x:Class="Ion.Sdk.DemoApp.Views.BlackBox"
             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:Ion.Sdk.DemoApp.Views"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:ici="clr-namespace:Ion.Sdk.Ici;assembly=Ion.Sdk.Ici"
             xmlns:ddr="clr-namespace:Ion.Sdk.Ddr;assembly=Ion.Sdk.Ddr"
             xmlns:viewModels="clr-namespace:Ion.Sdk.DemoApp.Views.ViewModels"
             xmlns:fxConveters="clr-namespace:Ion.Sdk.DemoApp.Framework.Converters;assembly=Ion.Sdk.DemoApp.Shared"
             xmlns:converters="clr-namespace:Ion.Sdk.DemoApp.Views.Converters;assembly=Ion.Sdk.DemoApp.Shared"
             xmlns:controls="clr-namespace:Ion.Sdk.DemoApp.Views.Controls;assembly=Ion.Sdk.DemoApp.Shared"
             mc:Ignorable="d"
             d:DesignHeight="450"
             d:DesignWidth="800"
             x:Name="View">
    <UserControl.Resources>
        <local:BlackBoxKeysTemplateSelector x:Key="BlackBoxKeysTemplateSelector" />
        <converters:InfoToTextConverter x:Key="InfoToTextConverter" />
        <fxConveters:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
        <Style x:Key="Button.ToolBar.Key"
               TargetType="Button"
               BasedOn="{StaticResource Button.ToolBar}">
            <Setter Property="Width"
                    Value="auto" />
            <Setter Property="Padding"
                    Value="10 5" />
            <Setter Property="Content"
                    Value="{Binding}" />
            <Setter Property="ToolTip"
                    Value="{Binding}" />
            <Setter Property="Margin"
                    Value="2" />
            <Setter Property="Command"
                    Value="{Binding ElementName=View, Path=SendKeyCommand}" />
            <Setter Property="CommandParameter"
                    Value="{Binding}" />
        </Style>
        <DataTemplate DataType="{x:Type ici:Channel+BlackBox+Message+Keyboard}">
            <DataTemplate.Resources>
                <Style TargetType="TextBlock"
                       BasedOn="{StaticResource TextBlock.Content}">
                    <Setter Property="Margin"
                            Value="10 5" />
                </Style>
                <Style TargetType="Button"
                       BasedOn="{StaticResource Button.Classic}" />
            </DataTemplate.Resources>
            <Grid Margin="10"
                  MinWidth="250"
                  MaxWidth="350"
                  MinHeight="120"
                  MaxHeight="250">
                <Border Background="{StaticResource Brush.White}"
                        BorderBrush="{StaticResource Brush.Separator}"
                        BorderThickness="1"
                        Effect="{StaticResource Shadow.Popup}" />
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Path=Caption}"
                               FontWeight="SemiBold"
                               HorizontalAlignment="Left" />
                    <Grid Grid.Row="1"
                          Margin="10">
                        <TextBox x:Name="ValueTextBox"
                                 Style="{StaticResource TextBox.Classic}"
                                 PreviewTextInput="ValueTextBox_OnPreviewTextInput"
                                 VerticalAlignment="Center" />
                        <TextBlock Style="{StaticResource TextBlock.Hint}"
                                   Tag="{Binding ElementName=ValueTextBox}"
                                   Text="Enter value"
                                   VerticalAlignment="Center" />
                    </Grid>
                    <Border Grid.Row="2"
                            Background="{StaticResource Brush.Background}"
                            Margin="1 0 1 1"></Border>
                    <Button Grid.Row="2"
                            Style="{StaticResource Button.Classic}"
                            MinWidth="40"
                            Margin="2 5"
                            HorizontalAlignment="Center"
                            HorizontalContentAlignment="Center"
                            Content="{x:Static ici:BlackBoxMessageButtons.Ok}"
                            Command="{Binding ElementName=View, Path=SendResponseCommand}"
                            CommandParameter="{Binding ElementName=ValueTextBox, Path=Text}" />
                </Grid>
            </Grid>
        </DataTemplate>
        <DataTemplate DataType="{x:Type ici:Channel+BlackBox+Message+Request}">
            <DataTemplate.Resources>
                <Style TargetType="TextBlock"
                       BasedOn="{StaticResource TextBlock.Content}">
                    <Setter Property="Margin"
                            Value="10 5" />
                </Style>
                <Style TargetType="Button"
                       BasedOn="{StaticResource Button.Classic}" />
            </DataTemplate.Resources>
            <Grid Margin="10"
                  MinWidth="250"
                  MaxWidth="350"
                  MinHeight="120"
                  MaxHeight="250">
                <Border Background="{StaticResource Brush.White}"
                        BorderBrush="{StaticResource Brush.Separator}"
                        BorderThickness="1"
                        Effect="{StaticResource Shadow.Popup}" />
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Path=Caption}"
                               FontWeight="SemiBold"
                               HorizontalAlignment="Left" />
                    <TextBlock Grid.Row="1"
                               Text="{Binding Path=Text}"
                               TextWrapping="Wrap" />
                    <Border Grid.Row="2"
                            Background="{StaticResource Brush.Background}"
                            Margin="1 0 1 1"></Border>
                    <ItemsControl Grid.Row="2"
                                  ItemsSource="{Binding Path= AvailableResponses}"
                                  HorizontalAlignment="Center"
                                  Margin="1 0 1 1">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Style="{StaticResource Button.Classic}"
                                        Margin="2 5"
                                        HorizontalContentAlignment="Center"
                                        Content="{Binding}"
                                        Command="{Binding ElementName=View, Path=SendResponseCommand}"
                                        CommandParameter="{Binding}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </Grid>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Esc">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Height="8"
                                 Stretch="Uniform">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                                <Path.Data>
                                    <StreamGeometry>M28.935012,4.5030206C30.347,4.5030206,31.368011,4.6900018,32.000001,5.0650018L32.000001,8.199004C31.228012,7.6220082 30.366012,7.3330067 29.415008,7.3330067 28.35501,7.3330067 27.514007,7.6430043 26.894012,8.2629994 26.275009,8.8829945 25.965011,9.7390126 25.965011,10.831023 25.965011,11.891021 26.261001,12.72302 26.853012,13.328001 27.446014,13.932005 28.261001,14.234007 29.298004,14.234007 30.218002,14.234007 31.119003,13.946012 32.000001,13.369017L32.000001,16.339018C31.165008,16.822996 29.961013,17.065 28.386001,17.065 26.545013,17.065 25.055997,16.507017 23.918012,15.391996 22.780012,14.277006 22.210004,12.838011 22.210004,11.076018 22.210004,9.0410145 22.821012,7.4370106 24.040998,6.2629999 25.260999,5.0899957 26.892013,4.5030206 28.935012,4.5030206z M16.842006,4.5030206C17.372005,4.5030206 17.910001,4.5440057 18.456006,4.6260065 19.002004,4.7080072 19.540006,4.8269952 20.070005,4.9830011L20.070005,7.8359975C19.602003,7.5639943 19.101003,7.3590077 18.567007,7.2220143 18.033002,7.0859975 17.509006,7.0180043 16.994007,7.0180043 16.752002,7.0180043 16.524005,7.0390004 16.310001,7.0819996 16.096004,7.1249989 15.906002,7.1870106 15.743,7.2690114 15.579006,7.3510121 15.45,7.4560231 15.357006,7.5850209 15.263004,7.7140187 15.216007,7.8600148 15.216007,8.0240163 15.216007,8.2420033 15.286006,8.429015 15.427005,8.5850209 15.567005,8.7409962 15.750003,8.8749989 15.976002,8.9880055 16.201999,9.1020192 16.454006,9.2030018 16.731006,9.2920216 17.008007,9.382018 17.282001,9.4739979 17.555004,9.5680226 18.047002,9.7390126 18.491003,9.9259938 18.889005,10.128997 19.286008,10.331023 19.628004,10.568999 19.912008,10.842009 20.197004,11.11502 20.415006,11.434996 20.567007,11.800994 20.719007,12.167998 20.796003,12.605009 20.796003,13.111021 20.796003,13.821012 20.641004,14.427 20.333005,14.930021 20.025007,15.433012 19.616003,15.842008 19.105009,16.158018 18.594007,16.473997 18.006002,16.704008 17.339,16.84802 16.672,16.992002 15.980008,17.063993 15.263004,17.063993 13.945003,17.063993 12.725002,16.861997 11.602,16.456022L11.602,13.462004C12.210002,13.828001 12.817005,14.102018 13.421001,14.281004 14.025005,14.46002 14.596004,14.550016 15.135005,14.550016 15.790004,14.550016 16.306003,14.46002 16.684001,14.281004 17.062,14.102018 17.251003,13.828001 17.251003,13.462004 17.251003,13.227995 17.165004,13.033018 16.994007,12.877012 16.823001,12.721006 16.602001,12.58502 16.333003,12.468016 16.064006,12.351012 15.77,12.246001 15.45,12.152007 15.131,12.05902 14.823001,11.953002 14.526004,11.835997 14.051006,11.657012 13.631,11.464019 13.269,11.257995 12.906002,11.050994 12.602001,10.811004 12.357006,10.537993 12.111003,10.265014 11.923999,9.9500111 11.795001,9.5910023 11.666003,9.2319935 11.602,8.8070058 11.602,8.3160084 11.602,7.6450184 11.748003,7.0680226 12.041004,6.5850209 12.333003,6.1020197 12.723003,5.7060236 13.210002,5.3980096 13.698001,5.0899957 14.255001,4.8640131 14.883007,4.7190241 15.510005,4.5750116 16.164005,4.5030206 16.842006,4.5030206z M0,0L9.6719994,0 9.6719994,3.0760189 3.778001,3.0760189 3.778001,6.8070058 9.2630028,6.8070058 9.2630028,9.8710011 3.778001,9.8710011 3.778001,13.708006 10.059,13.708006 10.059,16.772001 0,16.772001z</StreamGeometry>
                                </Path.Data>
                            </Path>
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Enter">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Height="12">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                                <Path.Data>
                                    <StreamGeometry>M35.90625,57.9839553833008L42.140625,57.9839553833008 42.140625,91.0308303833008 16.125,91.0308303833008 21.984375,96.7027053833008 21.984375,103.593330383301 7.03125,88.0308303833008 7.03125,87.8433303833008 21.984375,72.2808303833008 21.984375,79.2183303833008 16.21875,84.7964553833008 35.90625,84.7964553833008 35.90625,57.9839553833008z</StreamGeometry>
                                </Path.Data>
                            </Path>
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Up">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Width="10">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                                  Data="{StaticResource Geometry.ArrowHead.Up}" />
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Down">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Width="10">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                                  Data="{StaticResource Geometry.ArrowHead.Down}" />
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Left">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Height="10"
                                 Margin="0 1 2 0">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                                  Data="{StaticResource Geometry.ArrowHead.Left}" />
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Right">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Height="10"
                                 Margin="0 2 0 1">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                                  Data="{StaticResource Geometry.ArrowHead.Right}" />
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
        <DataTemplate x:Key="Button.Template.Key.Option">
            <Button Style="{StaticResource Button.ToolBar.Key}">
                <Button.ContentTemplate>
                    <DataTemplate>
                        <Viewbox Stretch="Uniform"
                                 Height="10"
                                 Margin="0 2 0 1">
                            <Path Stretch="Uniform"
                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                                <Path.Data>
                                    <StreamGeometry>M22.699997,19.299993L22.699997,24.299993 26.199997,24.299993 26.199997,19.299993z M21.699997,18.399999L27.199997,18.399999 27.199997,20.59998 31.900009,20.59998 31.900009,23.199987 27.199997,23.199987 27.199997,25.400001 21.699997,25.400001 21.699997,23.199987 0,23.199987 0,20.59998 21.699997,20.59998z M16.900009,10.099978L16.900009,15.09998 20.400009,15.09998 20.400009,10.099978z M15.900009,9.0999776L21.400009,9.0999776 21.400009,11.299991 32,11.299991 32,13.899997 21.400009,13.899997 21.400009,16.099979 15.900009,16.099979 15.900009,13.899997 0,13.899997 0,11.299991 15.900009,11.299991z M22.699997,1L22.699997,6.0000011 26.199997,6.0000011 26.199997,1z M21.699997,0L27.199997,0 27.199997,2.199982 32,2.199982 32,4.7999889 27.199997,4.7999889 27.199997,7.0000016 21.699997,7.0000016 21.699997,4.7999889 0,4.7999889 0,2.199982 21.699997,2.199982z</StreamGeometry>
                                </Path.Data>
                            </Path>
                        </Viewbox>
                    </DataTemplate>
                </Button.ContentTemplate>
            </Button>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="Root">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid x:Name="ToolbarGrid"
              ZIndex="100">
            <Border BorderBrush="{StaticResource Brush.Separator}"
                    Background="{StaticResource Brush.White}"
                    BorderThickness="0 0 0 0">
                <Border.Effect>
                    <DropShadowEffect RenderingBias="Quality"
                                      BlurRadius="10"
                                      ShadowDepth="0"
                                      Opacity="0.5" />
                </Border.Effect>
            </Border>
            <StackPanel Orientation="Horizontal"
                        Margin="2 0">
                <ToggleButton x:Name="BaudRateToggleButton"
                              IsChecked="False"
                              Style="{StaticResource ToggleButton.ToolBar}"
                              Width="auto"
                              Content="{Binding ElementName=View, Path=SelectedBaudRate}">
                    <ToggleButton.ContentTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock x:Name="ContentText"
                                           Style="{StaticResource TextBlock.Content}"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding StringFormat={}{0} Baud}"
                                           Foreground="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=Foreground}" />
                            </Grid>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding}"
                                             Value="{x:Null}">
                                    <Setter TargetName="ContentText"
                                            Property="Text"
                                            Value="Select transfer speed" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ToggleButton.ContentTemplate>
                </ToggleButton>
                <Popup Placement="Bottom"
                       IsOpen="{Binding ElementName=BaudRateToggleButton, Path=IsChecked, Mode=TwoWay}"
                       PlacementTarget="{Binding ElementName=BaudRateToggleButton}"
                       StaysOpen="False"
                       VerticalOffset="5"
                       AllowsTransparency="True">
                    <Grid Margin="{StaticResource Margin.Content}"
                          MinWidth="100">
                        <Border Background="{StaticResource Brush.White}"
                                BorderThickness="1"
                                BorderBrush="{StaticResource Brush.Separator}"
                                Effect="{StaticResource Shadow.Popup}" />
                        <Grid Margin="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Border BorderThickness="0 0 0 0"
                                    Background="{StaticResource Brush.Background}"
                                    BorderBrush="{StaticResource Brush.Separator}">
                                <TextBlock Text="Select transfer speed"
                                           Margin="{StaticResource Margin.Text}"
                                           FontSize="{StaticResource Font.Size.Tiny}"
                                           Foreground="{StaticResource Brush.Accent.Strong}" />
                            </Border>
                            <ListBox Grid.Row="1"
                                     ItemsSource="{Binding ElementName=View, Path=AvailableBaudRates}"
                                     SelectedItem="{Binding ElementName=View, Path=SelectedBaudRate, Mode=TwoWay}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Background="Transparent"
                                              IsHitTestVisible="True">
                                            <TextBlock Text="{Binding StringFormat={}{0} Baud}"
                                                       Style="{StaticResource TextBlock.Content}"
                                                       Margin="{StaticResource Margin.Text}"
                                                       HorizontalAlignment="Right" />
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </Grid>
                    </Grid>
                    <Popup.Triggers>
                        <EventTrigger RoutedEvent="Border.MouseUp">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BaudRateToggleButton"
                                                                   Storyboard.TargetProperty="IsChecked">
                                        <DiscreteObjectKeyFrame KeyTime="0%">
                                            <DiscreteObjectKeyFrame.Value>
                                                <system:Boolean>False</system:Boolean>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Popup.Triggers>
                </Popup>
                <ToggleButton x:Name="PortToggleButton"
                              IsChecked="False"
                              Style="{StaticResource ToggleButton.ToolBar}"
                              Width="auto"
                              Content="{Binding ElementName=View, Path=SelectedPort}">
                    <ToggleButton.ContentTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto" />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>
                                <Grid x:Name="IconGrid"
                                      Width="20">
                                    <Viewbox x:Name="OnlineViewbox"
                                             Stretch="Uniform"
                                             Width="10"
                                             Visibility="Hidden">
                                        <Path Data="{StaticResource Geometry.Check.Circle}"
                                              Fill="{StaticResource Brush.Marker.Confirm}"
                                              Stretch="Uniform" />
                                    </Viewbox>
                                    <Viewbox x:Name="OfflineViewbox"
                                             Stretch="Uniform"
                                             Visibility="Hidden"
                                             Width="10">
                                        <Path Data="{StaticResource Geometry.Link.Offline}"
                                              Fill="{StaticResource Brush.Marker.Reject}"
                                              Stretch="Uniform" />
                                    </Viewbox>
                                    <Viewbox x:Name="LoadingViewbox"
                                             Stretch="Uniform"
                                             Width="10"
                                             Visibility="Hidden"
                                             RenderTransformOrigin="0.5, 0.5">
                                        <Viewbox.RenderTransform>
                                            <RotateTransform Angle="0" />
                                        </Viewbox.RenderTransform>
                                        <Path Data="{StaticResource Geometry.Loading.Circle}"
                                              Fill="{StaticResource Brush.Foreground}"
                                              Stretch="Uniform" />
                                    </Viewbox>
                                </Grid>
                                <TextBlock Grid.Column="1"
                                           x:Name="ContentText"
                                           Style="{StaticResource TextBlock.Content}"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding}"
                                           Foreground="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=Foreground}" />
                            </Grid>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding ElementName=View, Path=IsOnline}"
                                             Value="{x:Null}">
                                    <DataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard RepeatBehavior="Forever">
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingViewbox"
                                                                               Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0%">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                                <DoubleAnimation Storyboard.TargetName="LoadingViewbox"
                                                                 Storyboard.TargetProperty="RenderTransform.(RotateTransform.Angle)"
                                                                 Duration="0:0:2.5"
                                                                 To="359" />
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.EnterActions>
                                    <DataTrigger.ExitActions>
                                        <BeginStoryboard>
                                            <Storyboard RepeatBehavior="Forever">
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingViewbox"
                                                                               Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0%">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Hidden</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingViewbox"
                                                                               Storyboard.TargetProperty="RenderTransform.(RotateTransform.Angle)">
                                                    <DiscreteObjectKeyFrame KeyTime="0%">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <system:Double>0</system:Double>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </DataTrigger.ExitActions>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ElementName=View, Path=IsOnline}"
                                             Value="True">
                                    <Setter TargetName="OnlineViewbox"
                                            Property="Visibility"
                                            Value="Visible" />
                                    <Setter TargetName="OfflineViewbox"
                                            Property="Visibility"
                                            Value="Hidden" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ElementName=View, Path=IsOnline}"
                                             Value="False">
                                    <Setter TargetName="OnlineViewbox"
                                            Property="Visibility"
                                            Value="Hidden" />
                                    <Setter TargetName="OfflineViewbox"
                                            Property="Visibility"
                                            Value="Visible" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding}"
                                             Value="{x:Null}">
                                    <Setter TargetName="ContentText"
                                            Property="Text"
                                            Value="Select port" />
                                    <Setter TargetName="IconGrid"
                                            Property="Visibility"
                                            Value="Collapsed" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ToggleButton.ContentTemplate>
                </ToggleButton>
                <Popup Placement="Bottom"
                       IsOpen="{Binding ElementName=PortToggleButton, Path=IsChecked, Mode=TwoWay}"
                       PlacementTarget="{Binding ElementName=PortToggleButton}"
                       StaysOpen="False"
                       VerticalOffset="5"
                       AllowsTransparency="True">
                    <Grid Margin="{StaticResource Margin.Content}"
                          MinWidth="100">
                        <Border Background="{StaticResource Brush.White}"
                                BorderThickness="1"
                                BorderBrush="{StaticResource Brush.Separator}"
                                Effect="{StaticResource Shadow.Popup}" />
                        <Grid Margin="1"
                              HorizontalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Border BorderThickness="0 0 0 0"
                                    Background="{StaticResource Brush.Background}"
                                    BorderBrush="{StaticResource Brush.Separator}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="auto" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="Select port"
                                               Margin="{StaticResource Margin.Text}"
                                               FontSize="{StaticResource Font.Size.Tiny}"
                                               Foreground="{StaticResource Brush.Accent.Strong}" />
                                    <Button Grid.Column="1"
                                            Style="{StaticResource Button.ListItem}"
                                            MinWidth="0"
                                            Width="20"
                                            Height="auto"
                                            BorderThickness="0"
                                            ToolTip="Refresh"
                                            Command="{Binding ElementName=View, Path=RefreshAvailablePortsCommand}">
                                        <Button.ContentTemplate>
                                            <DataTemplate>
                                                <Viewbox Stretch="Uniform"
                                                         Width="10">
                                                    <Path Data="{StaticResource Geometry.Refresh}"
                                                          Fill="{StaticResource Brush.Accent.Strong}"
                                                          Stretch="Uniform" />
                                                </Viewbox>
                                            </DataTemplate>
                                        </Button.ContentTemplate>
                                    </Button>
                                </Grid>
                            </Border>
                            <StackPanel Orientation="Vertical"
                                        Grid.Row="1">
                                <ListBox ItemsSource="{Binding ElementName=View, Path=AvailablePorts}"
                                         SelectedItem="{Binding ElementName=View, Path=SelectedPort, Mode=TwoWay}">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Border Background="Transparent"
                                                    IsHitTestVisible="True">
                                                <TextBlock Text="{Binding}"
                                                           Style="{StaticResource TextBlock.Content}"
                                                           Margin="{StaticResource Margin.Text}" />
                                            </Border>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </StackPanel>
                        </Grid>
                    </Grid>
                    <Popup.Triggers>
                        <EventTrigger RoutedEvent="Border.MouseUp">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PortToggleButton"
                                                                   Storyboard.TargetProperty="IsChecked">
                                        <DiscreteObjectKeyFrame KeyTime="0%">
                                            <DiscreteObjectKeyFrame.Value>
                                                <system:Boolean>False</system:Boolean>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Popup.Triggers>
                </Popup>
                <Rectangle Width="1"
                           VerticalAlignment="Stretch"
                           Margin="2"
                           Fill="{StaticResource Brush.Separator}"></Rectangle>
                <Button x:Name="StartSingleTest"
                        Style="{StaticResource Button.ToolBar}"
                        Width="auto"
                        Content="Single Test"
                        ToolTip="Start Single Test"
                        Command="{Binding ElementName=View, Path=StartSingleTestCommand}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal"
                                        DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                        Margin="5 0">
                                <Viewbox Stretch="Uniform"
                                         Height="10">
                                    <Path Stretch="Uniform"
                                          Data="{StaticResource Geometry.Play}"
                                          Fill="{Binding Path=Foreground}" />
                                </Viewbox>
                                <TextBlock Style="{StaticResource TextBlock.Content}"
                                           Margin="5 0 0 0"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding Path=Content}" />
                            </StackPanel>
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
                <Button x:Name="StartAutoSequence"
                        Style="{StaticResource Button.ToolBar}"
                        Width="auto"
                        Content="AutoSeqence"
                        ToolTip="Start AutoSequence"
                        Command="{Binding ElementName=View, Path=StartAutoSequenceCommand}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal"
                                        DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                        Margin="5 0">
                                <Viewbox Stretch="Uniform"
                                         Height="10">
                                    <Path Stretch="Uniform"
                                          Data="{StaticResource Geometry.AutoSequence}"
                                          Fill="{Binding Path=Foreground}" />
                                </Viewbox>
                                <TextBlock Style="{StaticResource TextBlock.Content}"
                                           Margin="5 0 0 0"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding Path=Content}" />
                            </StackPanel>
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
                <Rectangle Width="1"
                           VerticalAlignment="Stretch"
                           Margin="2"
                           Fill="{StaticResource Brush.Separator}"></Rectangle>
                <Button x:Name="RequestKeysButton"
                        Style="{StaticResource Button.ToolBar}"
                        Width="auto"
                        Content="Request Keys"
                        ToolTip="Request available actions"
                        Command="{Binding ElementName=View, Path=RequestKeysCommand}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal"
                                        DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                        Margin="5 0">
                                <Viewbox Stretch="Uniform"
                                         Height="10">
                                    <Path Stretch="Uniform"
                                          Fill="{Binding Path=Foreground}">
                                        <Path.Data>
                                            <StreamGeometry>M24.299988,12.099996L28.700012,12.099996 28.700012,15.399999 24.299988,15.399999z M8.7999878,12.099996L23.099976,12.099996 23.099976,15.399999 8.7999878,15.399999z M3.2999878,12.099996L7.7000122,12.099996 7.7000122,15.399999 3.2999878,15.399999z M25.399963,7.6999957L28.700012,7.6999957 28.700012,10.999998 25.399963,10.999998z M21,7.6999957L24.299988,7.6999957 24.299988,10.999998 21,10.999998z M16.5,7.6999957L19.799988,7.6999957 19.799988,10.999998 16.5,10.999998z M12.099976,7.6999957L15.399963,7.6999957 15.399963,10.999998 12.099976,10.999998z M7.7000122,7.6999957L11,7.6999957 11,10.999998 7.7000122,10.999998z M3.2999878,7.6999957L6.5999756,7.6999957 6.5999756,10.999998 3.2999878,10.999998z M25.399963,3.300002L28.700012,3.300002 28.700012,6.5999972 25.399963,6.5999972z M21,3.300002L24.299988,3.300002 24.299988,6.5999972 21,6.5999972z M16.5,3.300002L19.799988,3.300002 19.799988,6.5999972 16.5,6.5999972z M12.099976,3.300002L15.399963,3.300002 15.399963,6.5999972 12.099976,6.5999972z M7.7000122,3.300002L11,3.300002 11,6.5999972 7.7000122,6.5999972z M3.2999878,3.300002L6.5999756,3.300002 6.5999756,6.5999972 3.2999878,6.5999972z M2.2000122,2.1999964L2.2000122,16.599996 29.799988,16.599996 29.799988,2.1999964z M0.70001221,5.6843419E-14L31.399963,5.6843419E-14C31.700012,-1.4528626E-07,32,0.30000284,32,0.6999965L32,18.099996C32,18.499997,31.700012,18.8,31.299988,18.8L0.70001221,18.8C0.29998779,18.8,0,18.499997,0,18.099996L0,0.6999965C0,0.30000284,0.29998779,-1.4528626E-07,0.70001221,5.6843419E-14z</StreamGeometry>
                                        </Path.Data>
                                    </Path>
                                </Viewbox>
                                <TextBlock Style="{StaticResource TextBlock.Content}"
                                           Margin="5 0 0 0"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding Path=Content}" />
                            </StackPanel>
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
                <Button x:Name="RequestActionsButton"
                        Style="{StaticResource Button.ToolBar}"
                        Width="auto"
                        Content="Request Actions"
                        ToolTip="Request available actions"
                        Command="{Binding ElementName=View, Path=RequestActionsCommand}">
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal"
                                        DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                        Margin="5 0">
                                <Viewbox Stretch="Uniform"
                                         Height="10">
                                    <Path Stretch="Uniform"
                                          Fill="{Binding Path=Foreground}"
                                          Data="{StaticResource Geometry.Action}" />
                                </Viewbox>
                                <TextBlock Style="{StaticResource TextBlock.Content}"
                                           Margin="5 0 0 0"
                                           FontSize="{StaticResource Font.Size.Small}"
                                           Text="{Binding Path=Content}" />
                            </StackPanel>
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
            </StackPanel>
        </Grid>
        <Grid x:Name="Contents"
              Grid.Row="1"
              Margin="0 5 0 0"
              ClipToBounds="True">
            <Grid.Resources>
                <Style x:Key="Grid.Popout"
                       TargetType="Grid">
                    <Setter Property="Opacity"
                            Value="0" />
                    <Setter Property="RenderTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleX="0.6"
                                            ScaleY="0.6" />
                        </Setter.Value>
                    </Setter>
                    <Setter Property="RenderTransformOrigin"
                            Value="0.5, 0.5" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=View, Path=IsOnline}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         Duration="0:0:0.6"
                                                         To="1" />
                                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)"
                                                         Duration="0:0:0.3"
                                                         EasingFunction="{StaticResource Ease.Out}"
                                                         To="1" />
                                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)"
                                                         Duration="0:0:0.3"
                                                         EasingFunction="{StaticResource Ease.Out}"
                                                         To="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         Duration="0:0:0.3"
                                                         To="0" />
                                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)"
                                                         Duration="0:0:0.3"
                                                         EasingFunction="{StaticResource Ease.Out}"
                                                         To="0.6" />
                                        <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)"
                                                         Duration="0:0:0.3"
                                                         EasingFunction="{StaticResource Ease.Out}"
                                                         To="0.6" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Resources>
            <Grid Grid.IsSharedSizeScope="True">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <TextBlock Grid.RowSpan="2"
                           Text="Select port to connect..."
                           VerticalAlignment="Center"
                           HorizontalAlignment="Center"
                           Opacity="0.5"
                           FontSize="{StaticResource Font.Size.Small}"
                           Style="{StaticResource TextBlock.Content}" />
                <Grid x:Name="ConfigurationGrid"
                      MinWidth="500"
                      HorizontalAlignment="Center"
                      Style="{StaticResource Grid.Popout}">
                    <Border Background="{StaticResource Brush.White}" />
                    <StackPanel>
                        <StackPanel.Resources>
                            <Style TargetType="Label"
                                   BasedOn="{StaticResource Label.Top}" />
                            <Style TargetType="TextBox"
                                   BasedOn="{StaticResource TextBox.Classic}" />
                        </StackPanel.Resources>
                        <Label Content="BlackBox Password" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto"
                                                  SharedSizeGroup="buttons_group" />
                            </Grid.ColumnDefinitions>
                            <PasswordBox x:Name="BlackBoxPasswordBox"
                                         Style="{StaticResource PasswordBox.Classic}"
                                         PasswordChanged="BlackBoxPasswordBox_OnPasswordChanged" />
                        </Grid>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <StackPanel>
                                <Label Content="Region" />
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBox x:Name="SelectedRegionTextBox"
                                             Text="{Binding Path=SelectedRegion, Converter={StaticResource InfoToTextConverter}}"
                                             IsReadOnly="True"
                                             Padding="2 3 30 3" />
                                    <ToggleButton x:Name="ExpandRegionsToggleButton"
                                                  Style="{StaticResource ToggleButton.Circle}"
                                                  HorizontalAlignment="Right"
                                                  Margin="2 3 3 3"
                                                  IsEnabled="{Binding Path=BlackBoxProgress.IsBusy, Converter={StaticResource InvertedBooleanConverter}}">
                                        <ToggleButton.ContentTemplate>
                                            <DataTemplate>
                                                <Viewbox Stretch="Uniform"
                                                         Margin="0 2 0 0"
                                                         Width="8">
                                                    <Path Data="{StaticResource Geometry.ArrowHead.Down}"
                                                          Stretch="Uniform"
                                                          Fill="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=Foreground}" />
                                                </Viewbox>
                                            </DataTemplate>
                                        </ToggleButton.ContentTemplate>
                                    </ToggleButton>
                                    <Popup Placement="Bottom"
                                           IsOpen="{Binding ElementName=ExpandRegionsToggleButton, Path=IsChecked, Mode=TwoWay}"
                                           PlacementTarget="{Binding ElementName=SelectedRegionTextBox}"
                                           StaysOpen="False"
                                           VerticalOffset="2"
                                           AllowsTransparency="True">
                                        <Grid Margin="{StaticResource Margin.Content}"
                                              Width="{Binding ElementName=SelectedRegionTextBox, Path=ActualWidth, Mode=OneWay}">
                                            <Border Background="{StaticResource Brush.White}"
                                                    BorderThickness="1"
                                                    BorderBrush="{StaticResource Brush.Separator}"
                                                    Effect="{StaticResource Shadow.Popup}" />
                                            <Grid Margin="1 1 1 1">
                                                <ScrollViewer x:Name="RegionsListScrollViewer"
                                                              MaxHeight="200">
                                                    <ScrollViewer.Resources>
                                                        <DataTemplate DataType="{x:Type ddr:RegionInfo}">
                                                            <Button Style="{StaticResource Button.TreeNode}"
                                                                    Content="{Binding Converter={StaticResource InfoToTextConverter}}"
                                                                    Command="{Binding ElementName=View, Path=SelectRegionCommand}"
                                                                    CommandParameter="{Binding}" />
                                                        </DataTemplate>
                                                    </ScrollViewer.Resources>
                                                    <ItemsControl ItemsSource="{Binding Path=RegionsList, Mode=OneWay}" />
                                                </ScrollViewer>
                                            </Grid>
                                        </Grid>
                                        <Popup.Triggers>
                                            <EventTrigger RoutedEvent="Button.Click">
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandRegionsToggleButton"
                                                                                       Storyboard.TargetProperty="IsChecked">
                                                            <DiscreteObjectKeyFrame KeyTime="0%">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <system:Boolean>False</system:Boolean>
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger>
                                        </Popup.Triggers>
                                    </Popup>
                                </Grid>
                            </StackPanel>
                            <StackPanel Grid.Column="1"
                                        Margin="5 0 0 0">
                                <Label Content="Measurement" />
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto"
                                                          SharedSizeGroup="buttons_group" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBox x:Name="SelectedMeasurementTextBox"
                                             Text="{Binding Path=SelectedMeasurementInfo, Converter={StaticResource InfoToTextConverter}}"
                                             IsReadOnly="True"
                                             Padding="2 3 30 3" />
                                    <TextBlock Style="{StaticResource TextBlock.Hint}"
                                               Text="Select measurement"
                                               Tag="{Binding ElementName=SelectedMeasurementTextBox}" />
                                    <ToggleButton x:Name="ExpandMeasurementsToggleButton"
                                                  Style="{StaticResource ToggleButton.Circle}"
                                                  HorizontalAlignment="Right"
                                                  Margin="2 3 3 3"
                                                  IsEnabled="{Binding Path=BlackBoxProgress.IsBusy, Converter={StaticResource InvertedBooleanConverter}}">
                                        <ToggleButton.ContentTemplate>
                                            <DataTemplate>
                                                <Viewbox Stretch="Uniform"
                                                         Margin="0 2 0 0"
                                                         Width="8">
                                                    <Path Data="{StaticResource Geometry.ArrowHead.Down}"
                                                          Stretch="Uniform"
                                                          Fill="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=Foreground}" />
                                                </Viewbox>
                                            </DataTemplate>
                                        </ToggleButton.ContentTemplate>
                                    </ToggleButton>
                                    <Popup Placement="Bottom"
                                           IsOpen="{Binding ElementName=ExpandMeasurementsToggleButton, Path=IsChecked, Mode=TwoWay}"
                                           PlacementTarget="{Binding ElementName=SelectedMeasurementTextBox}"
                                           StaysOpen="False"
                                           VerticalOffset="2"
                                           AllowsTransparency="True">
                                        <Grid Margin="{StaticResource Margin.Content}"
                                              Width="{Binding ElementName=SelectedMeasurementTextBox, Path=ActualWidth, Mode=OneWay}">
                                            <Border Background="{StaticResource Brush.White}"
                                                    BorderThickness="1"
                                                    BorderBrush="{StaticResource Brush.Separator}"
                                                    Effect="{StaticResource Shadow.Popup}" />
                                            <Grid Margin="1">
                                                <ScrollViewer x:Name="MeasurementsListScrollViewer"
                                                              MaxHeight="200">
                                                    <ItemsControl ItemsSource="{Binding Path=MeasurementsList, Mode=OneWay}">
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate DataType="{x:Type ddr:MeasurementInfo}">
                                                                <Button Style="{StaticResource Button.TreeNode}"
                                                                        Content="{Binding Converter={StaticResource InfoToTextConverter}}"
                                                                        Command="{Binding ElementName=View, Path=SelectMeasurementCommand}"
                                                                        CommandParameter="{Binding}"
                                                                        ToolTip="{Binding Path=Name}" />
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </ScrollViewer>
                                            </Grid>
                                        </Grid>
                                        <Popup.Triggers>
                                            <EventTrigger RoutedEvent="Button.Click">
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpandMeasurementsToggleButton"
                                                                                       Storyboard.TargetProperty="IsChecked">
                                                            <DiscreteObjectKeyFrame KeyTime="0%">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <system:Boolean>False</system:Boolean>
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger>
                                        </Popup.Triggers>
                                    </Popup>
                                    <Button Grid.Column="1"
                                            Style="{StaticResource Button.Circle}"
                                            Margin="5 2"
                                            Content="Start Single Test"
                                            Command="{Binding ElementName=View, Path=StartSingleTestCommand}">
                                        <Button.ContentTemplate>
                                            <DataTemplate>
                                                <Viewbox Stretch="Uniform"
                                                         Width="7"
                                                         Margin="1 1 0 0">
                                                    <Path x:Name="Path"
                                                          Data="{StaticResource Geometry.Play}"
                                                          Fill="{StaticResource Brush.Marker.Confirm}" />
                                                </Viewbox>
                                                <DataTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=IsEnabled}"
                                                                 Value="False">
                                                        <Setter TargetName="Path"
                                                                Property="Fill"
                                                                Value="{StaticResource Brush.Disabled}" />
                                                    </DataTrigger>
                                                </DataTemplate.Triggers>
                                            </DataTemplate>
                                        </Button.ContentTemplate>
                                    </Button>
                                </Grid>
                                <CheckBox Content="Touch Pre-Test"
                                          IsChecked="{Binding Path=TouchPreTest, Mode=TwoWay}" />
                            </StackPanel>
                        </Grid>
                        <Label Content="AutoSequence" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto"
                                                  SharedSizeGroup="buttons_group" />
                            </Grid.ColumnDefinitions>
                            <TextBox x:Name="AutoSequenceTextBox"
                                     Text="{Binding Path=AutoSequenceName, UpdateSourceTrigger=PropertyChanged}"
                                     HorizontalAlignment="Stretch" />
                            <TextBlock Style="{StaticResource TextBlock.Hint}"
                                       Text="Enter AutoSequence name"
                                       Tag="{Binding ElementName=AutoSequenceTextBox}" />
                            <Button Grid.Column="1"
                                    Style="{StaticResource Button.Circle}"
                                    Margin="5 2"
                                    Content="Start AutoSequence"
                                    Command="{Binding ElementName=View, Path=StartAutoSequenceCommand}">
                                <Button.ContentTemplate>
                                    <DataTemplate>
                                        <Viewbox Stretch="Uniform"
                                                 Width="8"
                                                 Margin="1 1 0 0">
                                            <Path x:Name="Path"
                                                  Data="{StaticResource Geometry.AutoSequence}"
                                                  Fill="{StaticResource Brush.Marker.Confirm}" />
                                        </Viewbox>
                                        <DataTemplate.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=IsEnabled}"
                                                         Value="False">
                                                <Setter TargetName="Path"
                                                        Property="Fill"
                                                        Value="{StaticResource Brush.Disabled}" />
                                            </DataTrigger>
                                        </DataTemplate.Triggers>
                                    </DataTemplate>
                                </Button.ContentTemplate>
                            </Button>
                        </Grid>
                        <CheckBox Content="Show intermediate results"
                                  IsChecked="{Binding Path=ShowIntermediateResults}"
                                  Margin="0 8 0 3" />
                    </StackPanel>
                </Grid>
                <Grid x:Name="ControlPanel"
                      Grid.Row="1"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Top"
                      Height="250"
                      MinWidth="500"
                      Margin="0 30 0 0"
                      Style="{StaticResource Grid.Popout}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto"
                                          SharedSizeGroup="buttons_group" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*"
                                       MaxHeight="450" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Border Grid.RowSpan="4"
                            BorderThickness="1"
                            BorderBrush="{StaticResource Brush.Black}"
                            Background="{StaticResource Brush.White}"
                            Effect="{StaticResource Shadow.Focus}"></Border>
                    <Border Background="{StaticResource Brush.Black}"
                            Margin="1 1 1 0"></Border>
                    <Border Grid.Row="1"
                            Margin="1 0"
                            BorderThickness="0 1 0 1"
                            BorderBrush="{StaticResource Brush.Separator}"
                            SnapsToDevicePixels="True" />
                    <TextBlock Text="BlackBox Terminal"
                               Style="{StaticResource TextBlock.Content}"
                               FontSize="{StaticResource Font.Size.Tiny}"
                               Foreground="{StaticResource Brush.White}"
                               Margin="2" />
                    <ContentControl x:Name="StatusContent"
                                    Grid.Row="1"
                                    Margin="10">
                        <Grid x:Name="StatusGrid">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Viewbox x:Name="LoadingViewbox"
                                     Stretch="Uniform"
                                     Width="10"
                                     RenderTransformOrigin="0.5, 0.5">
                                <Viewbox.RenderTransform>
                                    <RotateTransform Angle="0" />
                                </Viewbox.RenderTransform>
                                <Path Data="{StaticResource Geometry.Loading.Circle}"
                                      Fill="{StaticResource Brush.Foreground}"
                                      Stretch="Uniform" />
                                <Viewbox.Style>
                                    <Style TargetType="Viewbox">
                                        <Setter Property="Visibility"
                                                Value="Collapsed" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=BlackBoxProgress.IsBusy}"
                                                         Value="True">
                                                <DataTrigger.EnterActions>
                                                    <BeginStoryboard>
                                                        <Storyboard RepeatBehavior="Forever">
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
                                                                <DiscreteObjectKeyFrame KeyTime="0%">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Visible</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(RotateTransform.Angle)"
                                                                             Duration="0:0:2.5"
                                                                             To="359" />
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </DataTrigger.EnterActions>
                                                <DataTrigger.ExitActions>
                                                    <BeginStoryboard>
                                                        <Storyboard RepeatBehavior="Forever">
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
                                                                <DiscreteObjectKeyFrame KeyTime="0%">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Collapsed</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="RenderTransform.(RotateTransform.Angle)">
                                                                <DiscreteObjectKeyFrame KeyTime="0%">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <system:Double>0</system:Double>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </DataTrigger.ExitActions>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Viewbox.Style>
                            </Viewbox>
                            <TextBlock Grid.Column="1"
                                       Margin="10 0 0 1"
                                       Style="{StaticResource TextBlock.Content}"
                                       VerticalAlignment="Center"
                                       Text="{Binding Path=ActionInfo}" />
                            <Button Grid.Column="2"
                                    Content="Stop"
                                    Width="Auto"
                                    Margin="5 0 0 0"
                                    Command="{Binding ElementName=View, Path=StopCommand}">
                                <Button.Style>
                                    <Style TargetType="Button"
                                           BasedOn="{StaticResource Button.ToolBar}">
                                        <Setter Property="Visibility"
                                                Value="Hidden" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=BlackBoxProgress.IsBusy}"
                                                         Value="True">
                                                <Setter Property="Visibility"
                                                        Value="Visible" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Button.Style>
                                <Button.ContentTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal"
                                                    DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                                    Margin="5 0">
                                            <Viewbox Stretch="Uniform"
                                                     Height="10">
                                                <Path Stretch="Uniform"
                                                      Data="{StaticResource Geometry.Stop}"
                                                      Fill="Red" />
                                            </Viewbox>
                                            <TextBlock Style="{StaticResource TextBlock.Content}"
                                                       Margin="5 0 0 0"
                                                       FontSize="{StaticResource Font.Size.Small}"
                                                       Text="{Binding Path=Content}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </Button.ContentTemplate>
                            </Button>
                        </Grid>
                    </ContentControl>
                    <Grid x:Name="PanelContentGrid"
                          Grid.Row="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="auto"
                                              MinWidth="80" />
                        </Grid.ColumnDefinitions>
                        <ScrollViewer x:Name="InfoTextsScrollViewer"
                                      Margin="10 0 0 1">
                            <ItemsControl ItemsSource="{Binding Path=InfoTexts, Mode=OneWay}" />
                        </ScrollViewer>
                        <Grid Grid.Column="1"
                              Margin="0 0 1 0"
                              Visibility="{Binding Path=BlackBoxProgress.IsBusy, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border Grid.RowSpan="2"
                                    BorderThickness="1 0 0 0"
                                    BorderBrush="{StaticResource Brush.Separator.Strong}"
                                    Background="{StaticResource Brush.Background.Weak}"></Border>
                            <ScrollViewer Grid.Row="1"
                                          Margin="0 0 0 1">
                                <ItemsControl ItemsSource="{Binding Path=Actions, Mode=OneWay}"
                                              Margin="0">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Button Style="{StaticResource Button.ToolBar}"
                                                    Width="Auto"
                                                    Padding="5 0"
                                                    Margin="2"
                                                    Content="{Binding}"
                                                    Command="{Binding ElementName=View, Path=ExecuteActionCommand}"
                                                    CommandParameter="{Binding}">
                                                <Button.ContentTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Horizontal"
                                                                    DataContext="{Binding RelativeSource={RelativeSource AncestorType=Button}}"
                                                                    Margin="2">
                                                            <Viewbox Stretch="Uniform"
                                                                     Height="10">
                                                                <Path Stretch="Uniform"
                                                                      Fill="{Binding Path=Foreground}"
                                                                      Data="{StaticResource Geometry.Action}" />
                                                            </Viewbox>
                                                            <TextBlock Style="{StaticResource TextBlock.Content}"
                                                                       Margin="5 0 0 0"
                                                                       Text="{Binding Path=Content}" />
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </Button.ContentTemplate>
                                            </Button>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Grid>
                        <ContentControl HorizontalAlignment="Center"
                                        VerticalAlignment="Center">
                            <ContentControl.Style>
                                <Style TargetType="ContentControl">
                                    <Setter Property="Visibility"
                                            Value="Hidden" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=CurrentRequest, Converter={StaticResource NotNullToBooleanConverter}}"
                                                     Value="True">
                                            <Setter Property="Visibility"
                                                    Value="Visible" />
                                            <Setter Property="Content"
                                                    Value="{Binding Path=CurrentRequest, Mode=OneWay}" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </ContentControl.Style>
                        </ContentControl>
                    </Grid>
                    <Grid Grid.Row="3"
                          Margin="1 0 1 1"
                          Height="30"
                          Visibility="{Binding Path=BlackBoxProgress.IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <Border Background="{StaticResource Brush.Background}"
                                BorderThickness="0 1 0 0"
                                BorderBrush="{StaticResource Brush.Separator.Strong}" />
                        <ItemsControl x:Name="KeysItemsControl"
                                      ItemsSource="{Binding Path=Keys, Mode=OneWay}"
                                      ItemTemplateSelector="{StaticResource BlackBoxKeysTemplateSelector}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </Grid>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
