<UserControl x:Class="FLY.Thick.Base.UI.UiModule.DynAreaIO"
             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.UiModule" 
             xmlns:conv="clr-namespace:FLY.Thick.Base.UI.Converter"
             d:DesignWidth="250"
             mc:Ignorable="d" >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/FLY.Thick.Base.UI;component/Themes/DynAreaErrorStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <conv:IO2BitColorConverter x:Key="io2bitcolorconv" />
            <Style TargetType="Rectangle" x:Key="IOStyle">
                <Setter Property="Width"  Value="9" />
                <Setter Property="Height"  Value="20" />
                <Setter Property="Margin"  Value="1" />
            </Style>
            <Style x:Key="IOTextStyle" TargetType="TextBlock">
                <Setter Property="Foreground"  Value="{StaticResource Brushes.ThemeBackground}" />
                <Setter Property="HorizontalAlignment"  Value="Center" />
                <Setter Property="VerticalAlignment"  Value="Center" />
                <Setter Property="FontSize"  Value="9"/>
            </Style>

            <local:DynAreaIOVm x:Key="ioVm" IStatus = "0xff7f" OStatus = "0x0005" Hrs = "2000" IsForever="False" IsFlyAdHardwareVersion3="True"/>
            <local:DynAreaErrorVm2 x:Key="errorVm" IsError="False" ErrMsg="枫莱尔控制器连接断开 枫莱尔控制器连接断开"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Height="100" >
        <Button Style="{StaticResource Styles.Button.Empty}" d:DataContext="{StaticResource ioVm}" Command="{Binding OpenIoTipCmd}">
            <Grid>
                <Border Style="{StaticResource Styles.Module.Border}" >
                    <Grid Margin="2">

                        <Grid>
                            <UniformGrid Columns="20" Margin="2,0" VerticalAlignment="Top" HorizontalAlignment="Left"
                                     Visibility="{Binding IsFlyAdHardwareVersion3,Converter={StaticResource visbilityconv}}">
                                <UniformGrid.Resources>
                                    <Style TargetType="Rectangle" BasedOn="{StaticResource IOStyle}"/>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource IOTextStyle}"/>
                                </UniformGrid.Resources>

                                <!--X-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="X" />
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" />
                                    <TextBlock Text="0" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" />
                                    <TextBlock Text="4" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=8}" />
                                    <TextBlock Text="8" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=9}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=10}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=11}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=12}" />
                                    <TextBlock Text="12" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=13}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=14}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=15}" />
                                <!--Y-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="Y" />
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}"/>
                                    <TextBlock Text="0"/>
                                </Grid>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}"/>
                                    <TextBlock Text="4"/>
                                </Grid>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" />
                            </UniformGrid>
                            <UniformGrid Columns="15" Margin="2,0" VerticalAlignment="Top" HorizontalAlignment="Left"
                                     Visibility="{Binding IsFlyAdHardwareVersion2p1,Converter={StaticResource visbilityconv}}">
                                <UniformGrid.Resources>
                                    <Style TargetType="Rectangle" BasedOn="{StaticResource IOStyle}"/>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource IOTextStyle}"/>
                                </UniformGrid.Resources>

                                <!--X-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="X"/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" />
                                    <TextBlock Text="0" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" />
                                    <TextBlock Text="4" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=8}" />
                                    <TextBlock Text="8" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=9}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=10}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=11}" />
                                <!--Y-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="Y"/>
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}"/>
                                    <TextBlock Text="0"/>
                                </Grid>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                            </UniformGrid>
                            <UniformGrid Columns="15" Margin="2,0" VerticalAlignment="Top" HorizontalAlignment="Left"
                                     Visibility="{Binding IsFlyAdHardwareVersion2,Converter={StaticResource visbilityconv}}">
                                <UniformGrid.Resources>
                                    <Style TargetType="Rectangle" BasedOn="{StaticResource IOStyle}"/>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource IOTextStyle}"/>
                                </UniformGrid.Resources>

                                <!--X-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="I"/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}" />
                                    <TextBlock Text="1" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=4}" />
                                    <TextBlock Text="5" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=5}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=6}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=7}" />
                                <Grid/>
                                <Grid>
                                    <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=8}" />
                                    <TextBlock Text="9" />
                                </Grid>
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=9}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=10}" />
                                <Rectangle Fill="{Binding IStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=11}" />
                                <!--Y-->
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Margin="0" VerticalAlignment="Center" Text="O"/>
                                <Grid>
                                    <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=0}"/>
                                    <TextBlock Text="1"/>
                                </Grid>
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=1}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=2}" />
                                <Rectangle Fill="{Binding OStatus,Converter={StaticResource io2bitcolorconv},ConverterParameter=3}" />
                            </UniformGrid>
                        </Grid>
                        <Button Style="{StaticResource Styles.Button.Empty}" 
                            VerticalAlignment="Bottom" HorizontalAlignment="Right" 
                            Margin="0,25,0,0"
                            Command="{Binding OpenAccessCmd}">
                            <StackPanel Visibility="{Binding IsForever,Converter={StaticResource visbilityconv},ConverterParameter=HiddenWhenTrue}" >
                                <TextBlock Style="{StaticResource Styles.Module.Text.ItemHeader}" Text="{StaticResource str.DynArea.RemainingTime}" />
                                <StackPanel Orientation="Horizontal" Background="{StaticResource Brushes.Text.Black}" >
                                    <TextBlock Style="{StaticResource Styles.Module.Text.ItemValue}" Text="{Binding Hrs}" Foreground="{StaticResource Brushes.Text.White}" Padding="2,0"/>
                                    <TextBlock Style="{StaticResource Styles.Module.Text.ItemValue.Unit}" Text="{StaticResource str.DynArea.H}" Foreground="{StaticResource Brushes.Text.White}"/>
                                </StackPanel>
                            </StackPanel>
                        </Button>
                    </Grid>
                </Border>
            </Grid>
        </Button>
        <Button x:Name="grid_error" Style="{StaticResource DynAreaErrorStyle}" d:DataContext="{StaticResource errorVm}"
                Command="{Binding OpenWarningCmd}"/>
    </Grid>

</UserControl>
