<Window x:Class="ShanghaiEnvironmentalTechnology.ParameterConfigWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="参数配置界面" WindowState="Maximized"   Height="768" Width="1024"
        WindowStartupLocation="CenterScreen"
        Loaded="Window_Loaded" 
        Background="#F5F7FA">
    <Window.Resources>
        <!-- TextBlock 样式 -->
        <Style x:Key="BaseTextBlockStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Microsoft YaHei"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Foreground" Value="#333333"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="TextAlignment" Value="Right"/>
            <Setter Property="Margin" Value="5,5,10,5"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>

        <!-- TextBox 样式 -->
        <Style x:Key="BaseTextBoxStyle" TargetType="TextBox">
            <Setter Property="FontFamily" Value="Microsoft YaHei"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Foreground" Value="#333333"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="#CCCCCC"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="MinWidth" Value="100"/>
            <Setter Property="MaxWidth" Value="180"/>
            <Setter Property="MinHeight" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="5,2"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Border 
                            x:Name="border"
                            CornerRadius="20"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                            <ScrollViewer 
                                x:Name="PART_ContentHost"
                                Focusable="False"
                                HorizontalScrollBarVisibility="Hidden"
                                VerticalScrollBarVisibility="Hidden"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="border" Property="Opacity" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="border" Property="BorderBrush" Value="#007ACC"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Button 样式（增加宽度设置为50） -->
        <Style x:Key="BaseButtonStyle" TargetType="Button">
            <Setter Property="FontFamily" Value="Microsoft YaHei"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Background" Value="#007ACC"/>
            <Setter Property="BorderBrush" Value="#007ACC"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="10,5"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Width" Value="50"/>
            <!-- 按钮宽度设置为50 -->
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border 
                            x:Name="border"
                            CornerRadius="20"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                            <ContentPresenter 
                                x:Name="contentPresenter"
                                Focusable="False"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                Margin="{TemplateBinding Padding}"
                                RecognizesAccessKey="True"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="border" Property="Background" Value="#005A9E"/>
                                <Setter TargetName="border" Property="BorderBrush" Value="#005A9E"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="border" Property="Background" Value="#004A80"/>
                                <Setter TargetName="border" Property="BorderBrush" Value="#004A80"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="border" Property="Opacity" Value="0.6"/>
                                <Setter TargetName="contentPresenter" Property="Opacity" Value="0.6"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid Margin="10" x:Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- 标题区域 -->
        <TextBlock x:Name="TitleTextBlock"
                   Grid.Row="0" 
                   Text="参数配置" 
                   FontSize="18" 
                   FontWeight="Bold"
                   HorizontalAlignment="Center"
                   Margin="0,10,0,15"/>

        <!-- 主要内容区域 -->
        <ScrollViewer x:Name="MainScrollViewer"
                      Grid.Row="1" VerticalScrollBarVisibility="Auto" Margin="5">
            <StackPanel x:Name="ContentStackPanel"
                        Orientation="Vertical" Margin="5">
                <!-- 流量参数分组 -->
                <GroupBox x:Name="FlowParametersGroup"
                          Header="流量参数" Margin="0,5" Padding="10">
                    <StackPanel x:Name="FlowParametersStack">
                        <Grid x:Name="FlowGrid1" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 排气P -->
                            <TextBlock Text="排气P" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbExhaustP"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 流量P -->
                            <TextBlock Text="流量P" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbFlowP"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>

                            <!-- 吸P -->
                            <TextBlock Text="吸P" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="6"/>
                            <TextBox x:Name="TbInhaleP"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="7"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="8" Click="Tb_LostFocus"/>
                        </Grid>

                        <Grid x:Name="FlowGrid2" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 排气I -->
                            <TextBlock Text="排气I" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbExhaustI"   IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 流量I -->
                            <TextBlock Text="流量I" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbFlowI"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>

                            <!-- 吸I -->
                            <TextBlock Text="吸I" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="6"/>
                            <TextBox x:Name="TbInhaleI"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="7"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="8" Click="Tb_LostFocus"/>
                        </Grid>

                        <Grid x:Name="FlowGrid3" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 排气D -->
                            <TextBlock Text="排气D" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbExhaustD"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 流量D -->
                            <TextBlock Text="流量D" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbFlowD"   IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>

                            <!-- 吸D -->
                            <TextBlock Text="吸D" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="6"/>
                            <TextBox x:Name="TbInhaleD"   IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="7"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="8" Click="Tb_LostFocus"/>
                        </Grid>
                    </StackPanel>
                </GroupBox>

                <!-- PID参数分组 -->
                <GroupBox x:Name="PIDParametersGroup"
                          Header="PID参数" Margin="0,5" Padding="10">
                    <StackPanel x:Name="PIDParametersStack">
                        <Grid x:Name="PIDGrid1" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 呼PID加系数 -->
                            <TextBlock Text="呼PID加系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbExpiratoryPID"   IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 吸PID加系数 -->
                            <TextBlock Text="吸PID加系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbInspiratoryPID"   IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>
                        </Grid>

                        <Grid x:Name="PIDGrid2" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 排气流PID加系数 -->
                            <TextBlock Text="排气流PID加系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0" Width="120"/>
                            <TextBox x:Name="TbExhaustFlowPID"  IsReadOnly="True"  Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1" Margin="0,0,20,0"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Margin="0,0,20,0" Click="Tb_LostFocus"/>

                            <!-- 气阻PID加系数 -->
                            <TextBlock Text="气阻PID加系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbResistancePID"  IsReadOnly="True" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4"  Margin="0,0,10,0"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>
                        </Grid>
                    </StackPanel>
                </GroupBox>

                <!-- 流量系数分组 -->
                <GroupBox x:Name="CoefficientParametersGroup"
                          Header="流量系数" Margin="0,5" Padding="10">
                    <StackPanel x:Name="CoefficientParametersStack">
                        <Grid x:Name="CoefficientGrid1" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 呼流量系数 -->
                            <TextBlock Text="呼流量系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbExpiratoryFlowCoeff" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="1" IsReadOnly="True"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 吸流量系数 -->
                            <TextBlock Text="吸流量系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbInspiratoryFlowCoeff" Text="####" Style="{StaticResource BaseTextBoxStyle}" Grid.Column="4" IsReadOnly="True"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>
                        </Grid>

                        <Grid x:Name="CoefficientGrid2" Margin="5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <!-- 鼻口压力系数 -->
                            <TextBlock Text="鼻口压力系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="0"/>
                            <TextBox x:Name="TbNasalPressureCoeff" Text="####" Style="{StaticResource BaseTextBoxStyle}" IsReadOnly="True" Grid.Column="1"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="2" Click="Tb_LostFocus"/>

                            <!-- 连接口压力系数 -->
                            <TextBlock Text="连接口压力系数" Style="{StaticResource BaseTextBlockStyle}" Grid.Column="3"/>
                            <TextBox x:Name="TbInterfacePressureCoeff" Text="####" Style="{StaticResource BaseTextBoxStyle}"  IsReadOnly="True" Grid.Column="4"/>
                            <Button Content="设置" Style="{StaticResource BaseButtonStyle}" Grid.Column="5" Click="Tb_LostFocus"/>
                        </Grid>
                    </StackPanel>
                </GroupBox>
            </StackPanel>
        </ScrollViewer>

        <!-- 底部按钮区域 -->
        <StackPanel x:Name="ButtonStackPanel"
                    Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
            <Button x:Name="BtnCalibrateExpiratory"
                    Content="呼流量校准" Style="{StaticResource BaseButtonStyle}" Click="OnCalibrateExpiratoryClick" Width="100"/>
            <Button x:Name="BtnCalibrateInspiratory"
                    Content="吸流量校准" Style="{StaticResource BaseButtonStyle}" Click="OnCalibrateInspiratoryClick" Width="100"/>
            <Button x:Name="BtnHome"
                    Content="主页" Style="{StaticResource BaseButtonStyle}" Click="OnHomeButtonClick"/>
        </StackPanel>
    </Grid>
</Window>