wpf - 如何在 WPF C# 应用程序中的特定网格上创建嵌套网格
问题描述
在我的 WPF 应用程序中,我必须将 label(Baudrate And ComboBoxOfBaudrate, DataBits And ComboBoxOfDataBits, parityBits And ComboBoxOfParityBits, StopBit And ComboBoxof StopBits) 和组合框放在同一个网格上,这样当我放大窗口时,它们可以在没有任何更改的情况下显示在其看来。我打算在需要为标签和组合框划分的特定网格内使用嵌套网格。
<Window
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SerialReadAndWrite"
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="ATR220ReadAndWrite.MainWindow"
mc:Ignorable="d"
Title="ATR220ReadAndWrite" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="0.75*"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ComboBox x:Name="ComPortComboBox" Width="98" Height=" 17" SelectionChanged="ComPort_SelectionChanged" DropDownOpened="ComPort_DropDownOpened" IsSynchronizedWithCurrentItem="False" FontSize="10" FontFamily="Arial" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center"/>
<Label Content="PortNumber :" HorizontalAlignment="Center" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" FontSize="12"/>
<Label Content="PortSettings :" HorizontalAlignment="Center" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" FontSize="12" FontFamily="Arial"/>
<Image HorizontalAlignment="Left" Height="26" Margin="359,14,0,0" VerticalAlignment="Top" Width="29" RenderTransformOrigin="-0.23,0.36"/>
<ComboBox x:Name="BaudRateComboBox" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="98" Height="17" SelectionChanged="BaudRate_SelectionChanged" IsEnabled="False" IsReadOnly="True" FontSize="10" FontFamily="Arial" >
<System:String>115200</System:String>
<System:String>57600</System:String>
<System:String>38400</System:String>
<System:String>19200</System:String>
<System:String>14400</System:String>
<System:String>9600</System:String>
<System:String>4800</System:String>
</ComboBox>
<ComboBox x:Name="ParityComboBox" HorizontalAlignment="Center" Height="17" Grid.Column="1" Grid.Row="4" VerticalAlignment="Center" Width="98" SelectionChanged="Parity_SelectionChanged" IsEnabled="False" FontSize="10" FontFamily="Arial">
<System:String>Even</System:String>
<System:String>Mark</System:String>
<System:String>None</System:String>
<System:String>Odd</System:String>
<System:String>Space</System:String>
</ComboBox>
<ComboBox x:Name="DataBitsComboBox" HorizontalAlignment="Center" Height="17" Grid.Column="2" Grid.Row="2" VerticalAlignment="Center" Width="98" SelectionChanged="DataBits_SelectionChanged" IsEnabled="False" FontSize="10" FontFamily="Arial">
<System:String>5</System:String>
<System:String>6</System:String>
<System:String>7</System:String>
<System:String>8</System:String>
</ComboBox>
<ComboBox x:Name="StopBitsComboBox" HorizontalAlignment="Center" Height="17" Grid.Column="2" Grid.Row="4" VerticalAlignment="Center" Width="98" SelectionChanged="StopBits_SelectionChanged" IsEnabled="False" FontSize="10" FontFamily="Arial">
<System:String>One</System:String>
<System:String>Two</System:String>
<System:String>OnePointFive</System:String>
</ComboBox>
<Label Content="Baudrate" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="12" FontStyle="Italic" Width="62"/>
<Label Content="Parity" HorizontalAlignment="Center" Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="12" FontStyle="Italic" Width="62" />
<Label Content="DataBits" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="1" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="12" FontStyle="Italic" Width="62" />
<Label Content="StopBit" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="3" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="12" FontStyle="Italic" Width="62" />
<Button x:Name="ConnectButton" Content="Connect" HorizontalAlignment="Center" Grid.Column="2" Grid.Row="5" VerticalAlignment="Center" Width="75" Click="ConnectButton_Click" IsEnabled="False" Height="17" FontSize="10" FontFamily="Arial"/>
<Label Content="ProtocolType: " HorizontalAlignment="Center" Grid.Column="0" Grid.Row="5" VerticalAlignment="Center" FontSize="12" FontFamily="Arial" />
<ComboBox x:Name="ProtocolTypeComboBox" HorizontalAlignment="Center" Height="17" Grid.Column="1" Grid.Row="5" VerticalAlignment="Center" Width="98" SelectionChanged="ProtocolTypeComboBox_SelectionChanged" VerticalContentAlignment="Stretch" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" FontSize="10" FontFamily="Arial" IsEnabled="False">
<System:String>WLink</System:String>
</ComboBox>
<StatusBar HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="794">
<StatusBarItem FontSize="9" FontFamily="Arial" TextOptions.TextHintingMode="Fixed">
<TextBlock Name= "PortStatus"/>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
我还创建了用于显示一些数据的状态栏,但我根本看不到状态栏。
所以请有人指导我做这个方向,因为我对 WPF 知之甚少。
请查看放大窗口的图像,因为标签和 ComBoBox 分离得很好,我不喜欢它。 在此处输入图像描述
解决方案
推荐阅读
- android - Android:根据运行的设备设置包名称
- java - Use UUID in annotation interface as default value
- regex - 在创建密码期间由于某种原因无法在 xcode 中打开模式 U_REGEX_MISMATCHED_PAREN 我的应用程序无法访问该模式
- java - joinPoint.proceed() 有什么作用?
- r - 为什么我的 R 包导出导入包的功能?
- java - 我可以将JDK用于商业用途吗?
- c - C中的自定义shellcode?
- python - etsy-api-oauth1 PUT 请求从 python 发出时返回无效签名,但不是来自 Postman
- ssl - “让我们加密”SSL 证书是否适用于端口 2998 (wss/socket.io) 连接?
- excel - excel VBA中的区域日期格式