<Window x:Class="K11_CNC.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:K11_CNC.ViewModel"
        Title="K11-CNC-Messeinrichtung" FontSize="20" Height="1000" Width="1000">
    <Window.Resources>
        
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary  Source="Resources\NavigationButtons.xaml" />
            <ResourceDictionary Source="Resources\AnzeigeTextboxen.xaml" />
        </ResourceDictionary.MergedDictionaries>
            <local:MainViewModel x:Key="vm" />
        </ResourceDictionary>
       
    </Window.Resources>
    
    <Grid Background="{DynamicResource MainWindowBackgroudBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="40" />
            <RowDefinition Height="10*"/>
            <RowDefinition Height="60*"/>
            <RowDefinition Height="60*"/>
            <RowDefinition Height="100"/>
            <RowDefinition Height="40" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
            <ComboBox x:Name="cbxCOMport" Height="30" Width="180" VerticalAlignment="Center" />
            <Button Height="40" Width="100" VerticalAlignment="Bottom" Content="Open"
                x:Name="btnPortOpen" Click="btnPortOpen_Click">
            </Button>
        </StackPanel>

        <StackPanel  VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10" Orientation="Horizontal">
        </StackPanel>
        <Grid Grid.Row="3" Grid.Column="1" Margin="0,0,0,35">
            <Grid.Resources>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Margin" Value="8,8,8,8" />
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button x:Name="btnUp" Grid.Row="0" Grid.Column="1" Click="btnUp_Click">
                    <Image Source="pack://application:,,,/Images/up.png"/>
            </Button>
                <Button Template="{StaticResource btnround}" x:Name="btnStop" Grid.Column="1" Grid.Row="1" Content="stop" Click="btnStop_Click" />
            <Button Template="{StaticResource btnround}" x:Name="btnSave" Grid.Column="0" Grid.Row="0" Content="save"/>
            <Button x:Name="btnDown" Grid.Row="2" Grid.Column="1" Click="btnDown_Click">
                <Image Source="pack://application:,,,/Images/down.png"/>
            </Button>
            <Button x:Name="btnLeft" Grid.Row="1" Grid.Column="0" Click="btnLeft_Click">
                <Image Source="pack://application:,,,/Images/previous.png"/>
            </Button>

            <Button x:Name="btnRight" Grid.Row="1" Grid.Column="2" Click="btnRight_Click">
                <Image Source="pack://application:,,,/Images/right.png"/>
            </Button>

            <TextBox x:Name="tbxSpeed" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Grid.Row="2" Width="80" HorizontalContentAlignment="Center" Text="400"/>
            <Label Content="Speed" HorizontalAlignment="Center" Grid.Row="2" Margin="0,0,0,70"/>
            <TextBox x:Name="tbxSteps" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Grid.Row="2" Width="80" HorizontalContentAlignment="Center" Text="400"/>
            <Label Content="Steps" HorizontalAlignment="Center" Grid.Row="2" Grid.Column="2" VerticalAlignment="Top"/>
            <RadioButton x:Name="rbnCruise" Grid.Column="2" Content="cruise" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" IsChecked="False"/>
        </Grid>
        <Label Grid.Column="1" Content="DALI A/V" HorizontalAlignment="Left" Grid.Row="3" VerticalAlignment="Bottom"/>
        <TextBox x:Name="tbxDALIadr" Grid.Column="1" HorizontalAlignment="Center" Margin="0,0,0,5" Grid.Row="3" VerticalAlignment="Bottom" Width="60" HorizontalContentAlignment="Center" Text="17"/>
        <TextBox x:Name="tbxDALIval" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,10,5" Grid.Row="3" VerticalAlignment="Bottom" Width="60" HorizontalContentAlignment="Center" Text="240"/>
        <Label Content="Port Status:" HorizontalAlignment="Left" Margin="4,0,0,0" Grid.Row="6" VerticalAlignment="Center"/>
        <Label x:Name="lblPortStatus" Content="disconnected" HorizontalAlignment="Right" Margin="0,0,5,0" Grid.Row="6" VerticalAlignment="Center"/>

        <StackPanel x:Name="stpMotorData" Grid.Row="6" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
            <Label Content="X:" HorizontalAlignment="Left" Margin="4,0,0,0" VerticalAlignment="Center"/>
            <Label Content="{Binding Path=PosX}" x:Name="lblXPos" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <Label Content="Y:" HorizontalAlignment="Left" Margin="4,0,0,0" VerticalAlignment="Center"/>
            <Label Content="{Binding Path=PosY}"  x:Name="lblYPos"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <!--
            <Label Content="Z:" HorizontalAlignment="Left" Margin="4,0,0,0" VerticalAlignment="Center"/>
            <Label x:Name="lblZPos" Content="......" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            -->
        </StackPanel>
        <Grid Grid.Column="2" Grid.Row="3">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button Content="go home" x:Name="btnHome" Grid.Column="0" Grid.Row="0" Click="btnHome_Click"/>
            <Button Content="span" x:Name="btnSpan" Grid.Column="1" Grid.Row="0"/>
        </Grid>
        <ListView ItemsSource="{Binding PositionsView, Mode=OneWay}" Grid.Row="4" Grid.ColumnSpan="3" SelectionMode="Single" Name="listView">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Changed}" Header="*" Width="40" />
                    <GridViewColumn DisplayMemberBinding="{Binding Id.Value}" Header="ID" Width="60" />
                    <GridViewColumn DisplayMemberBinding="{Binding XPos.Value}" Header="XPos" Width="75"/>
                    <GridViewColumn DisplayMemberBinding="{Binding YPos.Value}" Header="YPos" Width="75"/>
                    <GridViewColumn DisplayMemberBinding="{Binding ZPos.Value}" Header="ZPos" Width="75"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Dwell.Value}" Header="Dwell" Width="75" />
                    <GridViewColumn DisplayMemberBinding="{Binding DaliAdr.Value}" Header="DALI Adr" Width="100" />
                    <GridViewColumn DisplayMemberBinding="{Binding DaliVal.Value}" Header="DALI Val" Width="100" />
                </GridView>
            </ListView.View>
        </ListView>
        <DockPanel Grid.Row="5" VerticalAlignment="Top" Height="50" Background="LightGray" LastChildFill="False" >
            <Button Width="50" Command="{Binding FirstCommand}"  Template="{StaticResource navFirst}"  Margin="3"/>
            <Button Width="50" Command="{Binding PreviousCommand}" Template="{StaticResource navPrevious}" Margin="3"/>
            <Button Width="50" Command="{Binding RunCommand}"  Template="{StaticResource run}" Margin="30,0,0,3"/>
            <Button Width="50" Command="{Binding NextCommand}" Template="{StaticResource navNext}" Margin="30,0,0,3"/>
            <Button Width="50" Command="{Binding LastCommand}" Template="{StaticResource navLast}" Margin="3"/>

        </DockPanel>
        <TextBox Grid.Row="5" Height="40" Width="250" HorizontalAlignment="Center" VerticalAlignment="Bottom"
                 HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                 Margin="5" Text="{Binding ActualPosition, Mode=OneWay}" FontSize="18"/>
        <Grid Grid.Row="5" Grid.Column="1" DataContext="{Binding SelectedItem, ElementName=listView}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="ID"/>
            <Label Grid.Row="0" Grid.Column="1" Content="X"/>
            <Label Grid.Row="0" Grid.Column="2" Content="Y"/>
            <!-- <Label Grid.Row="0" Grid.Column="2" Content="Z"/> -->
            <Label Grid.Row="0" Grid.Column="3" Content="dw"/>
            <Label Grid.Row="0" Grid.Column="4" Content="Adr"/>
            <Label Grid.Row="0" Grid.Column="5" Content="Val"/>
            <TextBox DataContext="{Binding Id}" Text="{Binding Value}" Name="tbxID" Grid.Row="1" Grid.Column="0" />
            <TextBox local:FocusControl.Focus="{Binding Source={StaticResource vm}, Path=SetFocus, Mode=TwoWay}" DataContext="{Binding XPos}" Text="{Binding Value}" Name="tbxXpos"  Grid.Row="1" Grid.Column="1" />
            <TextBox DataContext="{Binding YPos}" Text="{Binding Value}" Name="tbxYpos" Grid.Row="1" Grid.Column="2" />
            <!-- <TextBox DataContext="{Binding ZPos}" Text="{Binding Value}" Name="tbxZpos" Grid.Row="1" Grid.Column="2" /> -->
            <TextBox DataContext="{Binding Dwell}" Text="{Binding Value}" Name="tbxDwell" Grid.Row="1" Grid.Column="3" />
            <TextBox DataContext="{Binding DaliAdr}" Text="{Binding Value}" Name="tbxDaliAdr" Grid.Row="1" Grid.Column="4" />
            <TextBox DataContext="{Binding DaliVal}" Text="{Binding Value}" Name="tbxDaliVal" Grid.Row="1" Grid.Column="5" />
        </Grid>
        <Grid Grid.Row="5" Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Button Width="Auto" Margin="3" Grid.Row="0" Grid.Column="0"
                    Command="ApplicationCommands.New" Content="{Binding Text, Source={x:Static ApplicationCommands.New}}" />
            <Button Width="Auto" Margin="3" Grid.Row="0" Grid.Column="1"
                    Command="ApplicationCommands.Save" Content="{Binding Text,Source={x:Static ApplicationCommands.Save}}"/>
            <Button Width="Auto" Margin="3" Grid.Row="1" Grid.Column="0"
                    Command="ApplicationCommands.Delete" Content="{Binding Text, Source={x:Static ApplicationCommands.Delete}}"/>
            <Button Width="Auto" Margin="3" Grid.Row="1" Grid.Column="1"
                    Command="ApplicationCommands.Undo" Content="{Binding Text, Source={x:Static ApplicationCommands.Undo}}" />
        </Grid>
    </Grid>
</Window>
