<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:app="clr-namespace:GoAccelerator"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:engine="clr-namespace:GoAcceleratorEngine;assembly=GoAcceleratorEngine"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:tb="http://www.hardcodet.net/taskbar"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:GoAcceleratorEngine="clr-namespace:GoAcceleratorEngine" x:Class="GoAccelerator.MainWindow"
        x:Name="MainWindowInstance"
        MinWidth="380"
        Background="{DynamicResource WindowBG}"
        Closing="Window_Closing"
        FontFamily="{DynamicResource DefaultFontFamily}"
        FontSize="{DynamicResource DefaultFontSize}"
        Foreground="{DynamicResource DefaultFontColor}"
        Icon="Resources/AppIcon.ico"
        ResizeMode="NoResize"
        ShowInTaskbar="{Binding ShowTaskbarIcon, Source={StaticResource GlobalSettings}}"
        SizeToContent="WidthAndHeight"
        Visibility="{Binding ShowMainWindowOnStartup, Converter={StaticResource GlobalBoolToVisibilityConverter}, Mode=OneTime, Source={StaticResource GlobalSettings}}"
        WindowStartupLocation="CenterScreen"
        mc:Ignorable="d" Loaded="MainWindowInstance_Loaded">

    <Window.DataContext>
        <engine:SensorsVM />
    </Window.DataContext>

    <Grid Margin="{DynamicResource WindowContentPadding}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <tb:TaskbarIcon DoubleClickCommand="{Binding ShowWindowCommand, ElementName=MainWindowInstance}"
                        IconSource="/Resources/AppIcon16x16.ico"
                        ToolTipText="Gocator Accelerator">
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="SensorManager"
                              Click="MenuItem_Click"
                              Header="_Main Window" />
                    <MenuItem x:Name="Settings"
                              Click="MenuItem_Click"
                              Header="_Settings" />
                    <Separator />
                    <MenuItem x:Name="Exit"
                              Click="MenuItem_Click"
                              Header="E_xit" />
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>
        <Image Width="32"
               Height="32"
               Margin="0,0,0,-10"
               HorizontalAlignment="Right"
               Source="Resources/AppLogo.png">
            <Image.Effect>
                <DropShadowEffect BlurRadius="0"
                                  Direction="-90"
                                  Opacity="0.5"
                                  ShadowDepth="2"
                                  Color="White" />
            </Image.Effect>
        </Image>
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="90" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid Margin="0,-14,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid Margin="0,5,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock VerticalAlignment="Bottom"
                               FontWeight="Bold"
                               Style="{DynamicResource TextBlockStyle}"
                               Text="Sensors" />
                    <Button Grid.Column="1"
                            Margin="2,0,0,4"
                            Command="{Binding RefreshCommand}"
                            Style="{DynamicResource ButtonStyle}"
                            ToolTip="Refresh Sensors"
                            IsEnabled="{Binding SensorIsBusy, Converter={StaticResource GlobalInverseBoolConverter}}">
                        <Rectangle Width="16"
                                   Height="16"
                                   Margin="-3"
                                   Fill="{DynamicResource IconRefresh}" />

                    </Button>
                </Grid>

                <ListBox x:Name="lstSensors" Grid.Row="1"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Stretch"
                         BorderBrush="#FFB7B7B7"
                         BorderThickness="1"
                         Foreground="{DynamicResource DefaultFontColor}"
                         ItemsSource="{Binding Sensors}"
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         SelectedItem="{Binding SelectedSensor}"
                         MaxHeight="220">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="16" />
                                </Grid.ColumnDefinitions>
                                <TextBlock  Text="{Binding Id}" />
                                <TextBlock  Grid.Column="1" Text=" " />
                                <Image Margin="0,0"  Grid.Column="2" Visibility="{Binding AccelerationEnabled,Converter={StaticResource GlobalBoolToVisibilityConverter}}" Height="16" Width="16" Source="Resources/AppIcon16x16.ico" IsEnabled="False"/>
                                
                                
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <StackPanel Grid.Row="2"
                            Margin="0,0,0,-3"
                            Orientation="Horizontal">
                    <TextBlock Style="{DynamicResource TextBlockStyleSmall}" Text="Version " />
                    <TextBlock Style="{DynamicResource TextBlockStyleSmall}" Text="{Binding FirmwareVersion}" />
                    
                </StackPanel>
            </Grid>

            <Border Grid.Column="1">

                <Grid Margin="10,0,0,0">

                    <StackPanel DataContext="{Binding SelectedSensor}">

                        <GroupBox Header="Sensor Info" Style="{DynamicResource GroupBoxStyle}">

                            <StackPanel>

                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <TextBlock 
                              HorizontalAlignment="Right"
                              VerticalAlignment="Top"
                                               Style="{DynamicResource TextBlockStyle}"
                                               Text="Serial #:  " />
                                    <TextBlock Grid.Column="1"
                                               Style="{DynamicResource TextBlockStyle}"
                                               Text="{Binding Id}" />

                                    <TextBlock Grid.Row="1"
                                               Grid.Column="0"
                                               HorizontalAlignment="Right"
                                               Style="{DynamicResource TextBlockStyle}"
                                               Text="Status:  " />
                                    <TextBlock x:Name="txtStatus" Grid.Row="1"
                                               Grid.Column="1"
                                               Style="{DynamicResource TextBlockStyle}"
                                               Text="{Binding Status}" />
                                    <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" 
                                               Style="{DynamicResource TextBlockStyle}" 
                                               Text="URL:  " />
                                    <TextBlock Grid.Row="2" Grid.Column="1" 
                                               Style="{DynamicResource TextBlockStyle}">
                                        <Hyperlink Command="{Binding LaunchUrlCommand}" NavigateUri="{Binding Url}">
                                            <InlineUIContainer>
                                                <TextBlock Text="{Binding Url}" />
                                            </InlineUIContainer>
                                            </Hyperlink>
                                    </TextBlock>
                                </Grid>
                            </StackPanel>
                        </GroupBox>

                        <GroupBox Margin="0,5,0,5"
                                  Header="Network"
                                  Style="{DynamicResource GroupBoxStyle}">

                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                
                                <TextBlock 
                              HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="1" Style="{DynamicResource TextBlockStyle}" Text="IP:  " Margin="0,0,0,5" />
                                <ComboBox x:Name="cmbIP" 
                           Grid.Row="1" 
                           Grid.Column="1" 
                           SelectedItem="{Binding SelectedIp}" 
                           ItemsSource="{Binding IpSelectionList, Mode=OneWay}" 
                           
                           Margin="0,2"
                           Style="{DynamicResource ComboBoxStyle}"/>
                                <TextBlock 
                              HorizontalAlignment="Right" Grid.Row="2"
                                           VerticalAlignment="Center"
                                           Style="{DynamicResource TextBlockStyle}"
                                           Text="Web Port:  " />
                                <xctk:IntegerUpDown x:Name="spinWebport"  Grid.Row="2"
                                                    Grid.Column="1"
                                                    Margin="0,2"
                                                    HorizontalAlignment="Left"
                                                    
                                                    Maximum="65535"
                                                    Minimum="1"
                                                    Style="{DynamicResource IntegerUpDownStyle}"
                                                    Value="{Binding WebPort}" />
                                <TextBlock x:Name="spinnerCtrl" 
                              HorizontalAlignment="Right" Grid.Row="3"
                                           VerticalAlignment="Center"
                                           Style="{DynamicResource TextBlockStyle}"
                                           Text="Base Port:  " />
                                <xctk:IntegerUpDown x:Name="spinBasePort"  Grid.Row="3"
                                                    Grid.Column="1"
                                                    Margin="0,2"
                                                    HorizontalAlignment="Left"
                                                    
                                                    Maximum="65535"
                                                    Minimum="1"
                                                    Style="{DynamicResource IntegerUpDownStyle}"
                                                    Value="{Binding BasePort}" />
                                <Button  Grid.Row="3" x:Name="btnReset" Grid.Column="3" Margin="0,4,0,0"
                                    HorizontalAlignment="Right"
                                    Content="Reset Port"
                                    SnapsToDevicePixels="True"
                                    Style="{DynamicResource ButtonStyle}" Click="btnReset_Click"  >
                                </Button>
                            </Grid>
                        </GroupBox>
                        <Button x:Name="btnStart" Margin="0,4,0,0"
                                HorizontalAlignment="Right"
                                Content="Start"
                                SnapsToDevicePixels="True"
                                Style="{DynamicResource ButtonStyle}" Click="btnStart_Click" >
                           
                        </Button>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>
    </Grid>
</Window>
