<UserControl
    x:Class="BPASmartClient.Control.ShopDeviceConfigView"
    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:BPASmartClient.Control"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource"
    xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel"
    xmlns:vmm="clr-namespace:BPASmartClient.Model;assembly=BPASmartClient.Model"
    d:DesignHeight="900"
    d:DesignWidth="1200"
    mc:Ignorable="d">

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

                    <vm:ShopDeviceConfigViewModel x:Key="sdv" />

                    <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="InputTextboxStyle" TargetType="TextBox">
                        <Setter Property="Margin" Value="3,0,0,0" />
                        <Setter Property="BorderThickness" Value="0" />
                        <Setter Property="CaretBrush" Value="{StaticResource TitleBorderColor}" />
                        <Setter Property="Foreground" Value="{StaticResource TitleBorderColor}" />
                        <Setter Property="FontSize" Value="14" />
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="VerticalAlignment" Value="Center" />
                    </Style>

                    <Style x:Key="TextBoxStyle" TargetType="TextBox">
                        <Setter Property="Height" Value="30" />
                        <Setter Property="Margin" Value="0,0,20,0" />
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="21" />
                        <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>

                    <Style x:Key="TreeviewItemStyle" TargetType="TreeViewItem">
                        <Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" />
                        <Setter Property="FontFamily" Value="楷体" />
                        <Setter Property="FontSize" Value="18" />
                    </Style>

                    <!--#region 右键菜单样式-->
                    <!--  自定义ContextMenu的外观样式  -->
                    <Style TargetType="{x:Type ContextMenu}">
                        <Setter Property="SnapsToDevicePixels" Value="True" />
                        <Setter Property="OverridesDefaultStyle" Value="True" />
                        <Setter Property="Grid.IsSharedSizeScope" Value="True" />
                        <Setter Property="Focusable" Value="False" />
                        <Setter Property="HasDropShadow" Value="True" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ContextMenu}">
                                    <Border
                                        Name="Border"
                                        Background="#6EA0B0"
                                        BorderBrush="#888888"
                                        BorderThickness="1">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="HasDropShadow" Value="true">
                                            <Setter TargetName="Border" Property="Padding" Value="0,3,0,3" />
                                            <Setter TargetName="Border" Property="CornerRadius" Value="4" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <!--  自定义菜单项之间的分隔符的样式  -->
                    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
                        <Setter Property="Height" Value="1" />
                        <Setter Property="Margin" Value="0,4,0,4" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type Separator}">
                                    <Border BorderBrush="#888888" BorderThickness="1" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <!--  TopLevelHeader  -->
                    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
                        <Border Name="Border">
                            <Grid>
                                <ContentPresenter
                                    Margin="6,3,6,3"
                                    ContentSource="Header"
                                    RecognizesAccessKey="True" />
                                <Popup
                                    Name="Popup"
                                    AllowsTransparency="True"
                                    Focusable="False"
                                    IsOpen="{TemplateBinding IsSubmenuOpen}"
                                    Placement="Bottom"
                                    PopupAnimation="Slide">
                                    <Border
                                        Name="SubmenuBorder"
                                        Background="#FFFFFF"
                                        BorderBrush="#888888"
                                        BorderThickness="1"
                                        SnapsToDevicePixels="True">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                    </Border>
                                </Popup>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                                <Setter TargetName="Popup" Property="PopupAnimation" Value="None" />
                            </Trigger>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="Green" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
                            </Trigger>
                            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                                <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4" />
                                <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" Value="#888888" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

                    <!--  TopLevelItem  -->
                    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
                        <Border Name="Border">
                            <Grid>
                                <ContentPresenter
                                    Margin="20,3,6,10"
                                    ContentSource="Header"
                                    RecognizesAccessKey="True" />
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="Blue" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" Value="#888888" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

                    <!--  SubmenuItem 自定义菜单项的外观样式  -->
                    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
                        <Border Name="Border">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut" />
                                    <ColumnDefinition Width="13" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter
                                    Name="Icon"
                                    Margin="6,2,6,2"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    ContentSource="Icon" />
                                <Border
                                    Name="Check"
                                    Width="13"
                                    Height="13"
                                    Margin="6,0,6,0"
                                    Background="#C0C0C0"
                                    BorderBrush="#404040"
                                    BorderThickness="1"
                                    Visibility="Hidden">
                                    <Path
                                        Name="CheckMark"
                                        Width="7"
                                        Height="7"
                                        Data="M 0 0 L 7 7 M 0 7 L 7 0"
                                        SnapsToDevicePixels="False"
                                        Stroke="#404040"
                                        StrokeThickness="1"
                                        Visibility="Visible" />
                                </Border>
                                <ContentPresenter
                                    Name="HeaderHost"
                                    Grid.Column="1"
                                    ContentSource="Header"
                                    RecognizesAccessKey="True" />
                                <TextBlock
                                    x:Name="InputGestureText"
                                    Grid.Column="2"
                                    Margin="5,2,0,2"
                                    Background="Green"
                                    DockPanel.Dock="Right"
                                    Text="{TemplateBinding InputGestureText}" />
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="Icon" Value="{x:Null}">
                                <Setter TargetName="Icon" Property="Visibility" Value="Hidden" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                            </Trigger>
                            <Trigger Property="IsCheckable" Value="true">
                                <Setter TargetName="Check" Property="Visibility" Value="Hidden" />
                                <Setter TargetName="Icon" Property="Visibility" Value="Hidden" />
                            </Trigger>
                            <!--  选中菜单项时的高亮颜色的trigger设置  -->
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="Green" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="Yellow" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

                    <!--  SubmenuHeader  -->

                    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
                        <Border Name="Border">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut" />
                                    <ColumnDefinition Width="13" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter
                                    Name="Icon"
                                    Margin="6,0,6,0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    ContentSource="Icon" />
                                <ContentPresenter
                                    Name="HeaderHost"
                                    Grid.Column="1"
                                    ContentSource="Header"
                                    RecognizesAccessKey="True" />
                                <TextBlock
                                    x:Name="InputGestureText"
                                    Grid.Column="2"
                                    Margin="5,2,2,2"
                                    DockPanel.Dock="Right"
                                    Text="{TemplateBinding InputGestureText}" />
                                <Path
                                    Grid.Column="3"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Data="M 0 0 L 0 7 L 4 3.5 Z"
                                    Fill="#404040" />
                                <Popup
                                    Name="Popup"
                                    AllowsTransparency="True"
                                    Focusable="False"
                                    HorizontalOffset="-4"
                                    IsOpen="{TemplateBinding IsSubmenuOpen}"
                                    Placement="Left"
                                    PopupAnimation="Slide">
                                    <Border
                                        Name="SubmenuBorder"
                                        Background="#FFFFFF"
                                        BorderBrush="#888888"
                                        BorderThickness="1"
                                        SnapsToDevicePixels="True">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                                    </Border>
                                </Popup>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="Icon" Value="{x:Null}">
                                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
                            </Trigger>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="#EEEEEE" />
                            </Trigger>
                            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                                <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4" />
                                <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#888888" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

                    <!--  MenuItem Style  -->

                    <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
                        <Setter Property="OverridesDefaultStyle" Value="True" />
                        <Style.Triggers>
                            <Trigger Property="Role" Value="TopLevelHeader">
                                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}" />
                                <Setter Property="Grid.IsSharedSizeScope" Value="true" />
                            </Trigger>
                            <Trigger Property="Role" Value="TopLevelItem">
                                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}" />
                            </Trigger>
                            <Trigger Property="Role" Value="SubmenuHeader">
                                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}" />
                            </Trigger>
                            <Trigger Property="Role" Value="SubmenuItem">
                                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>

                    <!--#endregion-->

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

    <UserControl.DataContext>
        <Binding Source="{StaticResource sdv}" />
    </UserControl.DataContext>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="55" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="250" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="1" Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition Width="0.5*" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="0.5*" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <TextBlock
                    HorizontalAlignment="Right"
                    Style="{StaticResource TextBlockStyle}"
                    Text="请选择店铺：" />

                <ComboBox
                    Name="shop"
                    Grid.Column="1"
                    Width="170"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    BorderBrush="#FF23CACA"
                    BorderThickness="1"
                    DropDownOpened="ComboBox_DropDownOpened"
                    FontFamily="楷体"
                    FontSize="20"
                    Foreground="#ff23caca"
                    IsEditable="False"
                    ItemsSource="{Binding Shops}"
                    SelectedIndex="0"
                    SelectionChanged="shop_SelectionChanged"
                    Style="{StaticResource ComboBoxStyle}"
                    Text="{Binding ClientDeviceType}" />

                <pry:IcoButton
                    Grid.Column="3"
                    Width="170"
                    HorizontalAlignment="Left"
                    Content="新建店铺"
                    FontSize="16"
                    Foreground="{StaticResource TextBlockForeground}"
                    IcoText="&#xe626;"
                    MouseLeftButtonDown="IcoButton_MouseLeftButtonDown"
                    Style="{StaticResource NewButtonStyle}" />

                <pry:IcoButton
                    Grid.Column="5"
                    Width="170"
                    HorizontalAlignment="Left"
                    Command="{Binding SaveData}"
                    Content="保存配置"
                    FontSize="16"
                    Foreground="{StaticResource TextBlockForeground}"
                    IcoText="&#xe626;"
                    Style="{StaticResource NewButtonStyle}" />

            </Grid>

        </Grid>

        <Grid Grid.Row="2" Background="#2200CAFF">

            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="250" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <!--#region 设备目录树-->
                <Grid>
                    <TreeView
                        Name="tv"
                        Background="Transparent"
                        BorderThickness="1"
                        ItemsSource="{Binding deviceConfig}"
                        SelectedItemChanged="TreeView_SelectedItemChanged">
                        <TreeView.Resources>

                            <!--  店铺信息  -->
                            <HierarchicalDataTemplate DataType="{x:Type vmm:DeviceConfigModelJson}" ItemsSource="{Binding deviceModels}">
                                <StackPanel>
                                    <TextBlock Style="{StaticResource TextBlockStyle}" Text="{Binding ShopName}">
                                        <TextBlock.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem
                                                    Command="{Binding NewDeviceCommand, Source={StaticResource sdv}}"
                                                    CommandParameter="{Binding}"
                                                    Header="新建设备" />
                                            </ContextMenu>
                                        </TextBlock.ContextMenu>
                                    </TextBlock>
                                </StackPanel>
                            </HierarchicalDataTemplate>

                            <!--  设备信息  -->
                            <HierarchicalDataTemplate DataType="{x:Type vmm:DeviceModel}" ItemsSource="{Binding communicationDevcies}">
                                <StackPanel>
                                    <TextBlock Style="{StaticResource TextBlockStyle}" Text="{Binding DeviceName}">
                                        <TextBlock.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem
                                                    Command="{Binding NewCommunicationCommand, Source={StaticResource sdv}}"
                                                    CommandParameter="{Binding}"
                                                    Header="新建通讯" />
                                                <MenuItem
                                                    Command="{Binding RemoveDeviceCommand, Source={StaticResource sdv}}"
                                                    CommandParameter="{Binding}"
                                                    Header="删除设备" />
                                            </ContextMenu>
                                        </TextBlock.ContextMenu>
                                    </TextBlock>
                                </StackPanel>
                            </HierarchicalDataTemplate>

                            <!--  通讯模块信息  -->
                            <DataTemplate DataType="{x:Type vmm:CommunicationModel}">
                                <StackPanel>
                                    <TextBlock Style="{StaticResource TextBlockStyle}" Text="{Binding CommunicationName}">
                                        <TextBlock.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem
                                                    Command="{Binding RemoveCommunicationCommand, Source={StaticResource sdv}}"
                                                    CommandParameter="{Binding}"
                                                    Header="删除通讯" />
                                            </ContextMenu>
                                        </TextBlock.ContextMenu>
                                    </TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </TreeView.Resources>
                    </TreeView>
                </Grid>
                <!--#endregion-->

                <Grid Grid.Column="1" Margin="10">

                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.1*" />
                        <RowDefinition Height="0.1*" />
                        <RowDefinition Height="0.1*" />
                        <RowDefinition Height="0.1*" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <!--#region 店铺参数-->
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <UniformGrid
                            Name="CommType"
                            Grid.Column="1"
                            VerticalAlignment="Center"
                            Columns="2"
                            Visibility="Collapsed">
                            <RadioButton
                                Name="rbNetwork"
                                Checked="rbNetwork_Checked"
                                Content="网口"
                                FontSize="16"
                                Foreground="{StaticResource TextBlockForeground}"
                                IsChecked="{Binding SelectedValue.communicationPar.IsNetworkPort, ElementName=tv, Mode=TwoWay}" />

                            <RadioButton
                                Name="rbSerial"
                                Checked="rbSerial_Checked"
                                Content="串口"
                                FontSize="16"
                                Foreground="{StaticResource TextBlockForeground}"
                                IsChecked="{Binding SelectedValue.communicationPar.IsSerialPort, ElementName=tv, Mode=TwoWay}" />
                        </UniformGrid>

                        <TextBlock
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="店铺名称：" />

                        <TextBox
                            Grid.Column="3"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding deviceConfig[0].ShopName}" />

                        <TextBlock
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="店铺ID：" />

                        <TextBox
                            Grid.Column="5"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding deviceConfig[0].ShopId}" />

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

                    <!--#region 设备参数-->
                    <Grid
                        Name="Device"
                        Grid.Row="1"
                        Visibility="Collapsed">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock
                            Grid.Column="0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="请选择设备模块：" />

                        <ComboBox
                            Grid.Column="1"
                            Width="170"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="#FF23CACA"
                            BorderThickness="1"
                            FontFamily="楷体"
                            FontSize="20"
                            Foreground="#ff23caca"
                            IsEditable="False"
                            ItemsSource="{Binding DeviceModels}"
                            Style="{StaticResource ComboBoxStyle}"
                            Text="{Binding SelectedValue.DeviceModule, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="设备名称：" />

                        <TextBox
                            Grid.Column="3"
                            Width="170"
                            Margin="0"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.DeviceName, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="设备ID：" />

                        <TextBox
                            Grid.Column="5"
                            Width="170"
                            Margin="0"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.DeviceId, ElementName=tv, Mode=TwoWay}" />

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

                    <!--#region TCP 通讯参数-->
                    <Grid
                        Name="Network"
                        Grid.Row="1"
                        Visibility="Collapsed">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock
                            Grid.Column="0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="IP地址：" />
                        <TextBox
                            Grid.Column="1"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.IPAddress, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="端口号：" />
                        <TextBox
                            Grid.Column="3"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.IPPort, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="站号：" />
                        <TextBox
                            Grid.Column="5"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.StationNo, ElementName=tv, Mode=TwoWay}" />

                    </Grid>

                    <!--#endregion-->

                    <!--#region 串口设备-->
                    <Grid
                        Name="Serial"
                        Grid.Row="1"
                        Grid.RowSpan="2"
                        Visibility="Collapsed">

                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock
                            Grid.Row="0"
                            Grid.Column="0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="端口号：" />
                        <ComboBox
                            Grid.Row="0"
                            Grid.Column="1"
                            Width="170"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="#FF23CACA"
                            BorderThickness="1"
                            FontFamily="楷体"
                            FontSize="20"
                            Foreground="#ff23caca"
                            IsEditable="False"
                            ItemsSource="{Binding Ports}"
                            SelectedIndex="0"
                            Style="{StaticResource ComboBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.SerialPort, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Row="0"
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="波特率：" />
                        <ComboBox
                            Grid.Row="0"
                            Grid.Column="3"
                            Width="170"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="#FF23CACA"
                            BorderThickness="1"
                            FontFamily="楷体"
                            FontSize="20"
                            Foreground="#ff23caca"
                            IsEditable="False"
                            ItemsSource="{Binding BaudRates}"
                            SelectedIndex="0"
                            Style="{StaticResource ComboBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.BaudRate, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Row="0"
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="奇偶：" />
                        <ComboBox
                            Grid.Row="0"
                            Grid.Column="5"
                            Width="170"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="#FF23CACA"
                            BorderThickness="1"
                            FontFamily="楷体"
                            FontSize="20"
                            Foreground="#ff23caca"
                            IsEditable="False"
                            ItemsSource="{Binding Paritys}"
                            SelectedIndex="0"
                            Style="{StaticResource ComboBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.Parity, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Row="1"
                            Grid.Column="0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="数据位：" />
                        <TextBox
                            Grid.Row="1"
                            Grid.Column="1"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.DataBits, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Row="1"
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="停止位：" />
                        <TextBox
                            Grid.Row="1"
                            Grid.Column="3"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.StopBits, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Row="1"
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="站号：" />
                        <TextBox
                            Grid.Row="1"
                            Grid.Column="5"
                            Width="170"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.communicationPar.StationNo, ElementName=tv, Mode=TwoWay}" />
                    </Grid>
                    <!--#endregion-->

                    <!--#region 通讯参数-->
                    <Grid
                        Name="GridCommunication"
                        Grid.Row="3"
                        Visibility="Collapsed">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                            <ColumnDefinition Width="0.5*" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock
                            Grid.Column="0"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="请选择通讯模块：" />

                        <ComboBox
                            Grid.Column="1"
                            Width="170"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="#FF23CACA"
                            BorderThickness="1"
                            FontFamily="楷体"
                            FontSize="20"
                            Foreground="#ff23caca"
                            IsEditable="False"
                            ItemsSource="{Binding CommunicationModel}"
                            Style="{StaticResource ComboBoxStyle}"
                            Text="{Binding SelectedValue.CommunicationModule, ElementName=tv, Mode=TwoWay}" />

                        <!--<TextBlock
                            Grid.Column="2"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="设备名称：" />

                        <TextBox
                            Grid.Column="3"
                            Width="170"
                            Margin="0"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.DeviceName, ElementName=tv, Mode=TwoWay}" />

                        <TextBlock
                            Grid.Column="4"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TextBlockStyle}"
                            Text="设备ID：" />

                        <TextBox
                            Grid.Column="5"
                            Width="170"
                            Margin="0"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TextBoxStyle}"
                            Text="{Binding SelectedValue.DeviceId, ElementName=tv, Mode=TwoWay}" />-->

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

                    <!--#region 设备交互数据配置-->
                    <Grid
                        x:Name="VarTab"
                        Grid.Row="4"
                        Visibility="Collapsed">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <!--#region 表头-->
                        <Grid Background="#dd2AB2E7">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.3*" />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </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" />
                            </Grid>

                            <TextBlock
                                Grid.Column="2"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                FontSize="16"
                                Foreground="{StaticResource TitleFontColor}"
                                Text="读取长度" />
                        </Grid>
                        <!--#endregion-->

                        <!--#region 表数据-->
                        <ScrollViewer
                            Grid.Row="1"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden">
                            <ItemsControl ItemsSource="{Binding SelectedValue.variables, ElementName=tv, Mode=TwoWay}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Height="30">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="0.3*" />
                                                <ColumnDefinition />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>


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

                                            <TextBox
                                                Grid.Column="1"
                                                Width="400"
                                                Margin="5,0,0,0"
                                                HorizontalAlignment="Left"
                                                Style="{StaticResource InputTextboxStyle}"
                                                Text="{Binding Address}" />

                                            <Border
                                                Grid.Column="1"
                                                BorderBrush="{StaticResource BorderSolid}"
                                                BorderThickness="1,0,1,0" />

                                            <TextBox
                                                Grid.Column="2"
                                                Width="400"
                                                HorizontalAlignment="Left"
                                                Style="{StaticResource InputTextboxStyle}"
                                                Text="{Binding ReadLeng}" />

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

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

                    </Grid>

                    <!--#endregion-->

                </Grid>

            </Grid>

        </Grid>

    </Grid>

</UserControl>
