<UserControl
    x:Class="BPA.SingleDevice.View.VarMonitorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:BPA.SingleDevice.View"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <!--#region 表格标题栏设置-->
        <Grid Background="#dd2AB2E7">
            <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"
                FontSize="22"
                Text="序号" />

            <Grid Grid.Column="1">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="22"
                    Text="变量名" />
                <Border
                    BorderBrush="Gray"
                    BorderThickness="2,0,2,0"
                    Cursor="SizeWE" />
            </Grid>

            <TextBlock
                Grid.Column="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="22"
                Text="PLC 地址" />

            <Grid Grid.Column="3">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="22"
                    Text="注释" />
                <Border
                    BorderBrush="Gray"
                    BorderThickness="2,0,0,0"
                    Cursor="SizeWE" />
            </Grid>

            <Grid Grid.Column="4">
                <TextBlock
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    FontSize="22"
                    Text="Modbus TCP 地址" />
                <Border
                    BorderBrush="Gray"
                    BorderThickness="2,0,2,0"
                    Cursor="SizeWE" />
            </Grid>

            <TextBlock
                Grid.Column="5"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="22"
                Text="当前值" />
        </Grid>
        <!--#endregion-->

        <!--#region 表格数据显示-->
        <ScrollViewer
            Grid.Row="1"
            HorizontalScrollBarVisibility="Hidden"
            VerticalScrollBarVisibility="Auto">
            <ItemsControl ItemsSource="{Binding VariableMonitors}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid x:Name="gr" Height="50">
                            <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="22"
                                Text="{Binding Id}" />

                            <Grid Grid.Column="1">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="22"
                                    Text="{Binding VarName}" />
                                <Border BorderBrush="Gray" BorderThickness="2,0,2,0" />
                            </Grid>

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

                            <Grid Grid.Column="3">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="22"
                                    Text="{Binding Notes}" />
                                <Border BorderBrush="Gray" BorderThickness="2,0,0,0" />
                            </Grid>

                            <Grid Grid.Column="4">
                                <TextBlock
                                    Margin="5,0,0,0"
                                    VerticalAlignment="Center"
                                    Background="Transparent"
                                    FontSize="22"
                                    Foreground="White"
                                    Text="{Binding ModbusTcpAddress}" />
                                <Border BorderBrush="Gray" BorderThickness="2,0,2,0" />
                            </Grid>

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

                            <Border
                                Grid.ColumnSpan="8"
                                BorderBrush="Gray"
                                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>