<UserControl x:Class="FLY.Thick.Base.UI.CtMicroGage"
             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:FLY.Thick.Base.UI"
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             mc:Ignorable="d" 

             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CtMicroGageStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:IO2BitColorConverter x:Key="io2bitcolorconv"/>
            
            <local:CtMircoGageVmUt x:Key="viewModel" 
                Thick="300.3" AD="12000" ADMax="65535" Position="5001" PosLength="8900" Posmm="500.1" Velocity="5.1" ControllerState="定点"
                OStatus="0x0005"
                IStatus="0xff7f"
                IsError="False"
                ErrMsg="枫莱尔控制器连接断开"
                />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid d:DataContext="{StaticResource viewModel}"  >
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Button Command="{Binding StopCmd}" Style="{StaticResource BtnStyle}" Background="{StaticResource MahApps.Brushes.ValidationSummary1}" >
                        <iconPacks:PackIconMaterial Kind="Close" Style="{StaticResource IconStyle}" />
                    </Button>
                    <Button Command="{Binding OrgCmd}" Style="{StaticResource BtnStyle}" >
                        <iconPacks:PackIconMaterial Kind="Adjust" Style="{StaticResource IconStyle}" />
                    </Button>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Button Command="{Binding BackwCmd}" Style="{StaticResource BtnStyle}"  >
                        <iconPacks:PackIconMaterial Kind="ArrowLeft" Style="{StaticResource IconStyle}"/>
                    </Button>
                    <Button Command="{Binding ForwCmd}" Style="{StaticResource BtnStyle}" >
                        <iconPacks:PackIconMaterial Kind="ArrowRight" Style="{StaticResource IconStyle}"/>
                    </Button>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="4,0">
                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <TextBlock Text="纵向" Style="{StaticResource ItemHeaderStyle}"  />
                        <TextBlock Style="{StaticResource ItemValueStyle2}"
                                   Text="{Binding FilmVelocity,StringFormat={}{0:F1},Mode=OneWay}" />
                        <TextBlock Style="{StaticResource ItemValueUnitStyle2}"
                                   Text="m/min"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
            <StackPanel Margin="2" Grid.Column="2" Width="250">


                <Grid Margin="2" Name="grid_ad" Background="{StaticResource MahApps.Brushes.Gray8}">
                    <Rectangle Fill="{StaticResource MahApps.Brushes.Gray5}" HorizontalAlignment="Left">
                        <Rectangle.Width>
                            <MultiBinding Converter="{StaticResource ratioconv}" Mode="OneWay">
                                <Binding Path="AD" />
                                <Binding Path="ADMax" />
                                <Binding Path="ActualWidth" ElementName="grid_ad"/>
                            </MultiBinding>
                        </Rectangle.Width>
                    </Rectangle>
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" >
                            <TextBlock Style="{StaticResource ItemHeaderStyle}" 
                                       Text="AD" />
                            <TextBlock Style="{StaticResource ItemValueStyle}"
                                       Text="{Binding AD}"  />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Grid.Column="1">
                            <TextBlock Style="{StaticResource ItemHeaderStyle}" 
                                       Text="测量" />
                            <TextBlock Style="{StaticResource ItemValueStyle}" 
                                       Text="{Binding Thick,StringFormat={}{0:F1}}" />
                        </StackPanel>
                    </Grid>
                </Grid>
                <Grid Margin="2" Background="{StaticResource MahApps.Brushes.Gray8}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <Rectangle Fill="{StaticResource MahApps.Brushes.Gray5}" HorizontalAlignment="Left" Grid.ColumnSpan="2">
                        <Rectangle.Width>
                            <MultiBinding Converter="{StaticResource ratioconv}" Mode="OneWay">
                                <Binding Path="Position" />
                                <Binding Path="PosLength" />
                                <Binding Path="ActualWidth" ElementName="grid_ad"/>
                            </MultiBinding>
                        </Rectangle.Width>
                    </Rectangle>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource ItemHeaderStyle}" 
                                   Text="横向&#13;位置"/>
                        <TextBlock Style="{StaticResource ItemValueStyle}" >
                            <Run Text="{Binding Position}"/>
                            <Run Text="|"/>
                        </TextBlock>
                        <TextBlock Style="{StaticResource ItemValueUnitStyle}">
                            <Run Text="{Binding Posmm,StringFormat={}{0:F1}}"/><Run Text="mm"/>
                        </TextBlock>
                    </StackPanel>
                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <TextBlock Style="{StaticResource ItemValueStyle}" 
                                   Text="{Binding Velocity,StringFormat={}{0:F1},Mode=OneWay}" />
                        <TextBlock Style="{StaticResource ItemValueUnitStyle}"
                                   Text="m/min"/>
                    </StackPanel>
                </Grid>
                <StackPanel >
                    <StackPanel Orientation="Horizontal" Margin="2">
                        <TextBlock Text="入" Style="{StaticResource ItemHeaderStyle}" />
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=15}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=14}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=13}" Style="{StaticResource IOStyle}"/>
                            <Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=12}" Style="{StaticResource IOStyle}"/>
                                <TextBlock Text="13" Style="{StaticResource IOTextStyle}"/>
                            </Grid>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=11}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=10}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=9}" Style="{StaticResource IOStyle}"/>
                            <Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=8}" Style="{StaticResource IOStyle}"/>
                                <TextBlock Text="9" Style="{StaticResource IOTextStyle}"/>
                            </Grid>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" Style="{StaticResource IOStyle}"/>
                            <Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" Style="{StaticResource IOStyle}"/>
                                <TextBlock Text="5" Style="{StaticResource IOTextStyle}"/>
                            </Grid>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" Style="{StaticResource IOStyle}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" Style="{StaticResource IOStyle}"/>
                            <Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" Style="{StaticResource IOStyle}"/>
                                <TextBlock Text="1" Style="{StaticResource IOTextStyle}"/>
                            </Grid>
                            
                            
                        </StackPanel>
                    </StackPanel>
                    <Grid Margin="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
                            <TextBlock Text="出" Style="{StaticResource ItemHeaderStyle}"  />
                            <StackPanel Orientation="Horizontal" Margin="4,0">
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" Style="{StaticResource IOStyle}"/>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" Style="{StaticResource IOStyle}"/>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" Style="{StaticResource IOStyle}"/>
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" Style="{StaticResource IOStyle}"/>
                                    <TextBlock Text="5" Style="{StaticResource IOTextStyle}"/>
                                </Grid>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="4,0">
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" Style="{StaticResource IOStyle}"/>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" Style="{StaticResource IOStyle}"/>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" Style="{StaticResource IOStyle}"/>
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" Style="{StaticResource IOStyle}"/>
                                    <TextBlock Text="1" Style="{StaticResource IOTextStyle}"/>
                                </Grid>
                            </StackPanel>

                        </StackPanel>
                        <Grid Margin="1" >
                            <TextBlock Text="{Binding ControllerState}" FontSize="16" FontFamily="Microsoft Sans Serif" HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="{StaticResource MahApps.Brushes.Text}"/>
                            <Grid Visibility="{Binding IsError,Converter={StaticResource visbilityconv}}" Background="{StaticResource MahApps.Brushes.ValidationSummary1}" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Path Margin="5,2" Fill="White" Stretch="Uniform" Width="20" Height="20" SnapsToDevicePixels="True" Data="{StaticResource Geometry_alert-circle-outline}"  >
                                    <Path.Style>
                                        <Style TargetType="Path">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsError}" Value="True">
                                                    <DataTrigger.EnterActions>
                                                        <BeginStoryboard>
                                                            <Storyboard RepeatBehavior="Forever" >
                                                                <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="00:00:01" />
                                                                <DoubleAnimation BeginTime="0:0:1" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="00:00:01" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </DataTrigger.EnterActions>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Path.Style>
                                </Path>
                                <Viewbox Grid.Column="1" MaxHeight="20">
                                    <TextBlock VerticalAlignment="Center" FontSize="12" Foreground="White" Text="{Binding ErrMsg}"/>
                                </Viewbox>
                            </Grid>
                        </Grid>
                    </Grid>
                </StackPanel>

            </StackPanel>
        </Grid>
    </Grid>
</UserControl>
