<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" 
             Background="#FF119EDA"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CtMicroGageStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <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 ValidationSummaryColor1}" >
                        <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>
            <StackPanel Margin="2" Grid.Column="2" Width="250">


                <Grid Margin="2" Name="grid_ad" Background="{StaticResource GrayBrush8}">
                    <Rectangle Fill="{StaticResource GrayBrush2}" 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 Text="AD" Style="{StaticResource ItemHeaderStyle}" FontFamily="Microsoft Sans Serif"/>
                            <TextBlock Text="{Binding AD}" FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Grid.Column="1">
                            <TextBlock Text="测量" Style="{StaticResource ItemHeaderStyle}" />
                            <TextBlock Text="{Binding Thick,StringFormat={}{0:F1}}" FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" />
                        </StackPanel>
                    </Grid>
                </Grid>
                <Grid Margin="2" Background="{StaticResource GrayBrush8}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <Rectangle Fill="{StaticResource GrayBrush2}" 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 Text="位置" Style="{StaticResource ItemHeaderStyle}" Foreground="{StaticResource BlackBrush}"/>
                        <TextBlock FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" Text="{Binding Position}" Foreground="{StaticResource BlackBrush}"/>
                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm_interval}" Text="|" FontSize="24" Foreground="{StaticResource BlackBrush}"/>
                        <TextBlock Text="{Binding Posmm,StringFormat={}{0:F1}}" Style="{StaticResource TextBlockStyle_FieldContent_mm}" FontSize="12" Foreground="{StaticResource BlackBrush}"/>
                        <TextBlock Style="{StaticResource TextBlockStyle_FieldContent_mm}" FontSize="12" Foreground="{StaticResource BlackBrush}" Text="mm"/>
                    </StackPanel>
                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <TextBlock Text="{Binding Velocity,StringFormat={}{0:F1},Mode=OneWay}" FontSize="24" FontFamily="Microsoft Sans Serif" TextAlignment="Center" HorizontalAlignment="Center" />
                        <TextBlock Text="m/min" Style="{StaticResource TextBlockStyle_FieldContent_mm}" FontSize="12" Foreground="Black"/>
                    </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=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}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=8}" Style="{StaticResource IOStyle}"/>
                        </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}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" Style="{StaticResource IOStyle}"/>
                        </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}"/>
                            <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" Style="{StaticResource IOStyle}"/>
                        </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=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}"/>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" Style="{StaticResource IOStyle}"/>
                            </StackPanel>
                        </StackPanel>
                        <Grid Margin="1" >
                            <TextBlock Text="{Binding ControllerState}" FontSize="16" FontFamily="Microsoft Sans Serif" HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="{StaticResource BlackBrush}"/>
                            <Grid Visibility="{Binding IsError,Converter={StaticResource visbilityconv}}" Background="{StaticResource ValidationSummaryColor1}" >
                                <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>
