<UserControl x:Class="SettingModule.Views.SettingView"
             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:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:prism="http://prismlibrary.com/"
             xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare"
             xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d"
             d:DesignHeight="700"
             d:DesignWidth="1200">
    <UserControl.Resources>
        <converters:LessThanConverter x:Key="LessThanConverter"/>
        <converters:BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
    </UserControl.Resources>

    <Border Background="#F5F7FA">
        <i:Interaction.Behaviors>
            <b:MouseDoubleClickBehavior
                Command="{Binding DataContext.RefreshCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
        </i:Interaction.Behaviors>

        <Grid x:Name="RootGrid" Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition>
                    <RowDefinition.Style>
                        <Style TargetType="RowDefinition">
                            <Setter Property="Height" Value="Auto"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                    <Setter Property="Height" Value="0"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </RowDefinition.Style>
                </RowDefinition>
                <RowDefinition Height="*"/>
                <RowDefinition>
                    <RowDefinition.Style>
                        <Style TargetType="RowDefinition">
                            <Setter Property="Height" Value="Auto"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                    <Setter Property="Height" Value="0"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </RowDefinition.Style>
                </RowDefinition>
            </Grid.RowDefinitions>

            <!-- ========== Row0：标题 ========== -->
            <TextBlock Grid.Row="0"
                       Text="{Binding TestStatus, StringFormat=设置界面 - {0}}"
                       FontSize="20" FontWeight="Bold"
                       Margin="4,0,0,8">
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>

            <!-- ========== Row1：主体（TabControl 切换两个面板）========== -->
            <TabControl Grid.Row="1"
                        Background="Transparent"
                        BorderThickness="0"
                        Padding="0">

                <!-- ============== Tab 1：设备列表 ============== -->
                <TabItem Header="设备列表">
                    <Grid Margin="0,8,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition>
                                <ColumnDefinition.Style>
                                    <Style TargetType="ColumnDefinition">
                                        <Setter Property="Width" Value="240"/>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                                <Setter Property="Width" Value="0"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ColumnDefinition.Style>
                            </ColumnDefinition>
                            <ColumnDefinition>
                                <ColumnDefinition.Style>
                                    <Style TargetType="ColumnDefinition">
                                        <Setter Property="Width" Value="6"/>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                                <Setter Property="Width" Value="0"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ColumnDefinition.Style>
                            </ColumnDefinition>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Border Grid.Column="0"
                                Background="White"
                                BorderBrush="#DDD" BorderThickness="1"
                                CornerRadius="4">
                            <Border.Style>
                                <Style TargetType="Border">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                            <DockPanel>
                                <Border DockPanel.Dock="Top"
                                        Background="#ECEFF4"
                                        Padding="8,4">
                                    <TextBlock Text="设备列表" FontWeight="Bold"/>
                                </Border>
                                <ListBox ItemsSource="{Binding DeviceList}"
                                         SelectedItem="{Binding SelectedDevice}"
                                         BorderThickness="0"
                                         HorizontalContentAlignment="Stretch">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="4,6">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <StackPanel Grid.Column="0">
                                                    <TextBlock Text="{Binding DeviceName}" FontWeight="Bold"/>
                                                    <TextBlock Text="{Binding DeviceType}"
                                                               Foreground="#888" FontSize="11"
                                                               Margin="0,2,0,0"/>
                                                </StackPanel>
                                                <StackPanel Grid.Column="1"
                                                            Orientation="Horizontal"
                                                            VerticalAlignment="Center">
                                                    <Border Width="8" Height="8" CornerRadius="4"
                                                            Margin="0,0,4,0" VerticalAlignment="Center">
                                                        <Border.Style>
                                                            <Style TargetType="Border">
                                                                <Setter Property="Background" Value="#CCC"/>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsEnabled}" Value="True">
                                                                        <Setter Property="Background" Value="#4CAF50"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Border.Style>
                                                    </Border>
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </DockPanel>
                        </Border>

                        <GridSplitter Grid.Column="1"
                                      HorizontalAlignment="Stretch"
                                      Background="Transparent">
                            <GridSplitter.Style>
                                <Style TargetType="GridSplitter">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                            <Setter Property="Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </GridSplitter.Style>
                        </GridSplitter>

                        <Border Grid.Column="2"
                                Background="White"
                                BorderBrush="#DDD" BorderThickness="1"
                                CornerRadius="4">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <Border Grid.Row="0"
                                        Background="#ECEFF4"
                                        Padding="10,6"
                                        BorderBrush="#DDD" BorderThickness="0,0,0,1">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0"
                                                   VerticalAlignment="Center"
                                                   FontWeight="Bold">
                                            <Run Text="配置："/>
                                            <Run Text="{Binding SelectedDevice.DeviceName, FallbackValue=未选中}"/>
                                        </TextBlock>
                                        <StackPanel Grid.Column="1" Orientation="Horizontal">
                                        
                                            <Button Content="保存" Command="{Binding SaveCommand}" Padding="12,4" Margin="6,0,0,0"/>
                                        </StackPanel>
                                    </Grid>
                                </Border>

                                <ScrollViewer Grid.Row="1"
                                              VerticalScrollBarVisibility="Auto"
                                              HorizontalScrollBarVisibility="Disabled"
                                              Padding="14">
                                    <StackPanel>
                                        <Border Background="White"
                                                BorderBrush="#E0E0E0" BorderThickness="1"
                                                CornerRadius="4" Padding="14"
                                                Margin="0,0,0,12">
                                            <StackPanel>
                                                <TextBlock Text="基本信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="100"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                    </Grid.RowDefinitions>

                                                    <TextBlock Grid.Row="0" Grid.Column="0" Text="设备名称：" VerticalAlignment="Center" Margin="0,4"/>
                                                    <TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4" 
                                                             Text="{Binding SelectedDevice.DeviceName, UpdateSourceTrigger=PropertyChanged}"/>

                                                    <TextBlock Grid.Row="1" Grid.Column="0" Text="设备类型：" VerticalAlignment="Center" Margin="0,4"/>
                                                    <TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
                                                             Text="{Binding SelectedDevice.DeviceType, UpdateSourceTrigger=PropertyChanged}"/>

                                                    <TextBlock Grid.Row="2" Grid.Column="0" Text="备注说明：" VerticalAlignment="Center" Margin="0,4"/>
                                                    <TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
                                                             Text="{Binding SelectedDevice.Remark, UpdateSourceTrigger=PropertyChanged}"/>

                                                    <TextBlock Grid.Row="3" Grid.Column="0" Text="启用状态：" VerticalAlignment="Center" Margin="0,4"/>
                                                    <CheckBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,6"
                                                              VerticalAlignment="Center"
                                                              IsChecked="{Binding SelectedDevice.IsEnabled}"
                                                              Content="启用此设备"/>

                                                    <TextBlock Grid.Row="4" Grid.Column="0" Text="连接状态：" VerticalAlignment="Center" Margin="0,4"/>
                                                    <StackPanel Grid.Row="4" Grid.Column="1" Orientation="Horizontal" Margin="0,6">
                                                        <Border Width="10" Height="10" CornerRadius="5"
                                                                VerticalAlignment="Center" Margin="0,0,6,0">
                                                            <Border.Style>
                                                                <Style TargetType="Border">
                                                                    <Setter Property="Background" Value="#CCC"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding SelectedDevice.IsConnected}" Value="True">
                                                                            <Setter Property="Background" Value="#4CAF50"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </Border.Style>
                                                        </Border>
                                                        <TextBlock VerticalAlignment="Center">
                                                            <TextBlock.Style>
                                                                <Style TargetType="TextBlock">
                                                                    <Setter Property="Text" Value="未连接"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding SelectedDevice.IsConnected}" Value="True">
                                                                            <Setter Property="Text" Value="已连接"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBlock.Style>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </Grid>
                                            </StackPanel>
                                        </Border>

                                        <Border Background="White"
                                                BorderBrush="#E0E0E0" BorderThickness="1"
                                                CornerRadius="4" Padding="14"
                                                Margin="0,0,0,12">
                                            <StackPanel>
                                                <TextBlock Text="连接参数" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>

                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="100"/>
                                                        <ColumnDefinition Width="*"/>
                                                        <ColumnDefinition Width="Auto"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto"/>
                                                        <RowDefinition Height="Auto"/>
                                                    </Grid.RowDefinitions>

                                                    <TextBlock Grid.Row="0" Grid.Column="0"
                                                               Text="连接方式："
                                                               VerticalAlignment="Center"
                                                               Margin="0,4"/>
                                                    <ComboBox  materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1"
                                                              Margin="0,4"
                                                              ItemsSource="{Binding ConnectionTypes}"
                                                              SelectedItem="{Binding SelectedDevice.ConnectionType,Mode=TwoWay}"/>
                                                    <Button Grid.Row="0" Grid.Column="2"
                                                            Content="配置..."
                                                            Margin="8,4,0,4" Padding="14,2"
                                                            Command="{Binding OpenConnectionConfigCommand}"/>

                                                    <!-- Tcp 参数预览 -->
                                                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
                                                                Margin="0,4,0,0" Orientation="Horizontal">
                                                        <StackPanel.Style>
                                                            <Style TargetType="StackPanel">
                                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="Tcp">
                                                                        <Setter Property="Visibility" Value="Visible"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </StackPanel.Style>
                                                        <TextBlock Foreground="#666" FontSize="12">
                                                            <Run Text="IP："/>
                                                            <Run Text="{Binding SelectedDevice.TcpConfig.IPAddress}"/>
                                                            <Run Text="  端口："/>
                                                            <Run Text="{Binding SelectedDevice.TcpConfig.Port}"/>
                                                            <Run Text="  发送/接收超时："/>
                                                            <Run Text="{Binding SelectedDevice.TcpConfig.SendTimeout}"/>
                                                            <Run Text="/"/>
                                                            <Run Text="{Binding SelectedDevice.TcpConfig.ReceiveTimeout}"/>
                                                            <Run Text=" ms"/>
                                                        </TextBlock>
                                                    </StackPanel>

                                                    <!-- 串口参数预览 -->
                                                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
                                                                Margin="0,4,0,0" Orientation="Horizontal">
                                                        <StackPanel.Style>
                                                            <Style TargetType="StackPanel">
                                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="Serial">
                                                                        <Setter Property="Visibility" Value="Visible"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </StackPanel.Style>
                                                        <TextBlock Foreground="#666" FontSize="12">
                                                            <Run Text="串口："/>
                                                            <Run Text="{Binding SelectedDevice.SerialPortConfig.PortName}"/>
                                                            <Run Text="  波特率："/>
                                                            <Run Text="{Binding SelectedDevice.SerialPortConfig.BaudRate}"/>
                                                            <Run Text="  数据/停止/校验："/>
                                                            <Run Text="{Binding SelectedDevice.SerialPortConfig.DataBits}"/>
                                                            <Run Text="/"/>
                                                            <Run Text="{Binding SelectedDevice.SerialPortConfig.StopBits}"/>
                                                            <Run Text="/"/>
                                                            <Run Text="{Binding SelectedDevice.SerialPortConfig.Parity}"/>
                                                        </TextBlock>
                                                    </StackPanel>

                                                    <!-- CAN 参数预览 -->
                                                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
                                                                Margin="0,4,0,0" Orientation="Horizontal">
                                                        <StackPanel.Style>
                                                            <Style TargetType="StackPanel">
                                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding SelectedDevice.ConnectionType}" Value="CAN">
                                                                        <Setter Property="Visibility" Value="Visible"/>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </StackPanel.Style>
                                                        <TextBlock Foreground="#666" FontSize="12">
                                                            <Run Text="设备类型："/>
                                                            <Run Text="{Binding SelectedDevice.CANConfig.DeviceType}"/>
                                                            <Run Text="  设备索引："/>
                                                            <Run Text="{Binding SelectedDevice.CANConfig.DeviceIndex}"/>
                                                            <Run Text="  仲裁/数据波特率："/>
                                                            <Run Text="{Binding SelectedDevice.CANConfig.ABitBaud}"/>
                                                            <Run Text="/"/>
                                                            <Run Text="{Binding SelectedDevice.CANConfig.DBitBaud}"/>
                                                            <Run Text="  终端电阻："/>
                                                            <Run Text="{Binding SelectedDevice.CANConfig.EnableTerminalResistance}"/>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </Grid>
                                            </StackPanel>
                                        </Border>

                                        <Border Background="White"
                                                BorderBrush="#E0E0E0" BorderThickness="1"
                                                CornerRadius="4" Padding="14">
                                            <!--<StackPanel>
                                                <TextBlock Text="高级设置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                                <TextBlock Foreground="#888" FontSize="12" TextWrapping="Wrap"
                                                           Text="超时、重试、缓存策略等高级选项后续在此扩展。"/>
                                            </StackPanel>-->
                                        </Border>
                                    </StackPanel>
                                </ScrollViewer>
                            </Grid>
                        </Border>
                    </Grid>
                </TabItem>

                <!-- ============== Tab 2：系统参数（编辑 SystemConfig）============== -->
                <TabItem Header="系统参数">
                    <Border Background="White"
                            BorderBrush="#DDD" BorderThickness="1"
                            CornerRadius="4"
                            Margin="0,8,0,0">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>

                            <Border Grid.Row="0"
                                    Background="#ECEFF4"
                                    Padding="10,6"
                                    BorderBrush="#DDD" BorderThickness="0,0,0,1">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0"
                                               Text="系统参数（SystemConfig）"
                                               VerticalAlignment="Center"
                                               FontWeight="Bold"/>
                                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                                        <Button Content="保存" Command="{Binding SaveCommand}" Padding="12,4" Margin="6,0,0,0"/>
                                    </StackPanel>
                                </Grid>
                            </Border>

                            <ScrollViewer Grid.Row="1"
                                          VerticalScrollBarVisibility="Auto"
                                          HorizontalScrollBarVisibility="Disabled"
                                          Padding="14">
                                <StackPanel>
                                    <Border Background="White"
                                            BorderBrush="#E0E0E0" BorderThickness="1"
                                            CornerRadius="4" Padding="14"
                                            Margin="0,0,0,12">
                                        <StackPanel>
                                            <TextBlock Text="基础设置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="140"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>

                                              

                                                <TextBlock Grid.Row="2" Grid.Column="0" Text="性能等级：" VerticalAlignment="Center" Margin="0,4"/>
                                                <Grid Grid.Row="2" Grid.Column="1" Margin="0,4">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*"/>
                                                        <ColumnDefinition Width="Auto"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Slider Grid.Column="0"
                                                            Minimum="100" Maximum="200"
                                                            TickFrequency="10" IsSnapToTickEnabled="True"
                                                            VerticalAlignment="Center"
                                                            Value="{Binding SystemConfig.PerformanceLevel}"/>
                                                    <TextBlock Grid.Column="1"
                                                               Text="{Binding SystemConfig.PerformanceLevel}"
                                                               VerticalAlignment="Center"
                                                               Margin="8,0,0,0"
                                                               MinWidth="30"/>
                                                </Grid>
                                            </Grid>
                                        </StackPanel>
                                    </Border>

                                    <Border Background="White"
                                            BorderBrush="#E0E0E0" BorderThickness="1"
                                            CornerRadius="4" Padding="14"
                                            Margin="0,0,0,12">
                                        <StackPanel>
                                            <TextBlock Text="公共变量（SharedParameterList）" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                            <TextBlock Foreground="#888" FontSize="12" TextWrapping="Wrap"
                                                       Text="每个台架可独立设置自己的通道号等整型变量；新建或打开程序时会用此处值覆盖程序中的同名变量。" Margin="0,0,0,10"/>
                                            <ItemsControl ItemsSource="{Binding SharedParameterList}">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid Margin="0,4">
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="160"/>
                                                                <ColumnDefinition Width="*"/>
                                                            </Grid.ColumnDefinitions>
                                                            <TextBlock Grid.Column="0" Text="{Binding ParameterName}" VerticalAlignment="Center"/>
                                                            <TextBox Grid.Column="1"
                                                                     VerticalAlignment="Center"
                                                                     materialDesign:HintAssist.Hint=""
                                                                     Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"/>
                                                        </Grid>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </StackPanel>
                                    </Border>

                                    <Border Background="White"
                                            BorderBrush="#E0E0E0" BorderThickness="1"
                                            CornerRadius="4" Padding="14"
                                            Margin="0,0,0,12">
                                        <StackPanel>
                                            <TextBlock Text="路径配置" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="140"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>

                                                <TextBlock Grid.Row="0" Grid.Column="0" Text="DLL 路径：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBox materialDesign:HintAssist.Hint="" Grid.Row="0" Grid.Column="1" Margin="0,4"
                                                         Text="{Binding SystemConfig.DLLFilePath, UpdateSourceTrigger=PropertyChanged}"/>

                                                <TextBlock Grid.Row="1" Grid.Column="0" Text="子程序路径：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBox materialDesign:HintAssist.Hint="" Grid.Row="1" Grid.Column="1" Margin="0,4"
                                                         Text="{Binding SystemConfig.SubProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>

                                                <TextBlock Grid.Row="2" Grid.Column="0" Text="默认程序文件：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBox materialDesign:HintAssist.Hint="" Grid.Row="2" Grid.Column="1" Margin="0,4"
                                                         Text="{Binding SystemConfig.DefaultProgramFilePath, UpdateSourceTrigger=PropertyChanged}"/>

                                                <TextBlock Grid.Row="3" Grid.Column="0" Text="默认 BLF 文件：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBox materialDesign:HintAssist.Hint="" Grid.Row="3" Grid.Column="1" Margin="0,4"
                                                         Text="{Binding SystemConfig.DefaultBLFFilePath, UpdateSourceTrigger=PropertyChanged}"/>

                                                <TextBlock Grid.Row="4" Grid.Column="0" Text="默认 DBC 文件：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBox materialDesign:HintAssist.Hint="" Grid.Row="4" Grid.Column="1" Margin="0,4"
                                                         Text="{Binding SystemConfig.DefaultDBCFilePath, UpdateSourceTrigger=PropertyChanged}"/>
                                            </Grid>
                                        </StackPanel>
                                    </Border>

                                    <Border Background="#FAFAFA"
                                            BorderBrush="#E0E0E0" BorderThickness="1"
                                            CornerRadius="4" Padding="14">
                                        <StackPanel>
                                            <TextBlock Text="只读信息" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition/>
                                                    <RowDefinition/>
                                                    <RowDefinition/>
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="140"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Grid.Row="0" Grid.Column="0" Text="标题：" VerticalAlignment="Center" />
                                                <TextBlock Grid.Row="0" Grid.Column="1" Margin="0,4"     Foreground="#555"
           Text="{Binding SystemConfig.Title}"/>

                                                <TextBlock Grid.Row="1" Grid.Column="0" Text="TSMaster 名称：" VerticalAlignment="Center" Margin="0,4"/>
                                                <TextBlock  Grid.Row="1" Grid.Column="1" Margin="0,4"     Foreground="#555"
           Text="{Binding SystemConfig.TSMasterName}"/>
                                                <TextBlock Grid.Row="2" Grid.Column="0" Text="系统数据目录：" VerticalAlignment="Center"/>
                                                <TextBlock Grid.Column="1" Grid.Row="2"
                                                           Text="{Binding SystemConfig.SystemPath}"  Margin="0,4"
                                                           Foreground="#555"
                                                           TextWrapping="Wrap"/>
                                            </Grid>
                                        </StackPanel>
                                    </Border>
                                </StackPanel>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </TabItem>
            </TabControl>

            <!-- ========== Row2：状态栏 ========== -->
            <Border Grid.Row="2"
                    Background="#ECEFF4"
                    Padding="8,4" Margin="0,6,0,0"
                    CornerRadius="2">
                <Border.Style>
                    <Style TargetType="Border">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <TextBlock Text="{Binding StatusMessage}"
                           Foreground="#444"
                           FontSize="12"/>
            </Border>
        </Grid>
    </Border>
</UserControl>
