<UserControl
    x:Class="HBLConsole.View.VariableMonitorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:HBLConsole.Converter"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:HBLConsole.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pry="clr-namespace:HBLConsole.PryUserControl;assembly=HBLConsole.PryUserControl"
    xmlns:vm="clr-namespace:HBLConsole.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="1000"
    mc:Ignorable="d">
    <UserControl.DataContext>
        <vm:VariableMonitorViewModel />
    </UserControl.DataContext>

    <UserControl.Resources>
        <ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <convert:TextDisplayConvert x:Key="textDisplayConvert" />
                    <convert:IsEnableConvert x:Key="isEnableConvert" />
                    <convert:AnalogAlarmConvert x:Key="analogAlarmConvert" />
                    <convert:DiscreteAlarmConvert x:Key="discreteAlarmConvert" />
                    <convert:AlarmTypeTextConvert x:Key="alarmTypeTextConvert" />
                    <SolidColorBrush x:Key="BorderSolid" Color="#5523CACA" />
                    <SolidColorBrush x:Key="FontColor" Color="#FF2AB2E7" />
                    <SolidColorBrush x:Key="TitleFontColor" Color="#ddd" />
                    <SolidColorBrush x:Key="CursorColor" Color="Aqua" />
                    <SolidColorBrush x:Key="TitleBorderColor" Color="#FF2AB2E7" />

                    <Style x:Key="TextBlockStyle" TargetType="TextBlock">
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="18" />
                        <Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                        <Setter Property="HorizontalAlignment" Value="Center" />
                    </Style>

                    <Style x:Key="TextBoxStyle" TargetType="TextBox">
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="22" />
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" />
                        <Setter Property="BorderBrush" Value="#FF23CACA" />
                        <Setter Property="CaretBrush" Value="Aqua" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>

                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <!--<RowDefinition Height="30" />-->
            <RowDefinition Height="30" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <!--<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
        -->
        <!--<Button
                Margin="20,0,20,0"
                Command="{Binding GenerateData}"
                Content="添加数据" />
            <Button
                Margin="20,0,20,0"
                Command="{Binding SaveData}"
                Content="保存数据" />-->
        <!--
        </StackPanel>-->

        <!--#region 表格标题栏设置-->
        <Grid Background="#dd2AB2E7">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.3*" />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition Width="0.7*" />
                <ColumnDefinition Width="0.7*" />
                <!--<ColumnDefinition Width="0.5*" />-->
            </Grid.ColumnDefinitions>
            <TextBlock
                Grid.Column="0"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="16"
                Foreground="{StaticResource TitleFontColor}"
                Text="ID" />

            <Grid Grid.Column="1">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="16"
                    Foreground="{StaticResource TitleFontColor}"
                    Text="变量名" />
                <Border
                    BorderBrush="{StaticResource TitleBorderColor}"
                    BorderThickness="1,0,1,0"
                    Cursor="SizeWE" />
            </Grid>

            <TextBlock
                Grid.Column="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="16"
                Foreground="{StaticResource TitleFontColor}"
                Text="PLC 地址" />


            <Grid Grid.Column="3">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="16"
                    Foreground="{StaticResource TitleFontColor}"
                    Text="注释" />
                <Border
                    BorderBrush="{StaticResource TitleBorderColor}"
                    BorderThickness="1,0,0,0"
                    Cursor="SizeWE" />
            </Grid>



            <Grid Grid.Column="4">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="16"
                    Foreground="{StaticResource TitleFontColor}"
                    Text="Modbus TCP 地址" />
                <Border
                    BorderBrush="{StaticResource TitleBorderColor}"
                    BorderThickness="1,0,1,0"
                    Cursor="SizeWE" />
            </Grid>

            <TextBlock
                Grid.Column="5"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="16"
                Foreground="{StaticResource TitleFontColor}"
                Text="当前值" />

        </Grid>
        <!--#endregion-->

        <!--#region 表格数据显示-->
        <ScrollViewer
            Grid.Row="1"
            HorizontalScrollBarVisibility="Hidden"
            VerticalScrollBarVisibility="Hidden">
            <ItemsControl ItemsSource="{Binding VariableMonitors}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid x:Name="gr" Height="30">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.3*" />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition Width="0.7*" />
                                <ColumnDefinition Width="0.7*" />
                            </Grid.ColumnDefinitions>

                            <TextBlock
                                Grid.Column="0"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Background="Transparent"
                                FontSize="14"
                                Foreground="{StaticResource FontColor}"
                                Text="{Binding Id}" />

                            <Grid Grid.Column="1">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="14"
                                    Foreground="{StaticResource FontColor}"
                                    Text="{Binding VarName}" />
                                <Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" />
                            </Grid>


                            <TextBlock
                                Grid.Column="2"
                                Margin="5,0,0,0"
                                VerticalAlignment="Center"
                                Background="Transparent"
                                FontSize="14"
                                Foreground="{StaticResource FontColor}"
                                Text="{Binding PLCAddress}" />

                            <Grid Grid.Column="3">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="14"
                                    Foreground="{StaticResource FontColor}"
                                    Text="{Binding Notes}" />
                                <Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,0,0" />
                            </Grid>

                            <Grid Grid.Column="4">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="14"
                                    Foreground="{StaticResource FontColor}"
                                    Text="{Binding ModbusTcpAddress}" />
                                <Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" />
                            </Grid>

                            <TextBlock
                                Grid.Column="5"
                                Margin="5,0,0,0"
                                VerticalAlignment="Center"
                                Background="Transparent"
                                FontSize="14"
                                Foreground="{StaticResource FontColor}"
                                Text="{Binding CurrentValue}" />

                            <Border
                                Grid.ColumnSpan="8"
                                BorderBrush="{StaticResource BorderSolid}"
                                BorderThickness="1" />

                        </Grid>

                        <DataTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="gr" Property="Background" Value="#112AB2E7" />
                            </Trigger>
                        </DataTemplate.Triggers>

                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
        <!--#endregion-->


    </Grid>
</UserControl>
