<Window x:Class="WpfApp2.MainWindow"
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:WpfApp2"
mc:Ignorable="d"
Title="串口工具" Height="800" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="串口号:" FontSize="25" Margin="5,25,5,25"/>
<Label Grid.Row="1" Content="波特率:" FontSize="25" Margin="5,25,5,25"/>
<Label Grid.Row="2" Content="数据位:" FontSize="25" Margin="5,25,5,25"/>
<Label Grid.Row="3" Content="停止位:" FontSize="25" Margin="5,25,5,25"/>
<Label Grid.Row="4" Content="校验位:" FontSize="25" Margin="5,25,5,25"/>
<ComboBox Grid.Column="1" Margin="10,25,10,25" Name="Portname"/>
<ComboBox Grid.Row="1" Grid.Column="1" Margin="10,25,10,25" Name="Baudrate"/>
<ComboBox Grid.Row="2" Grid.Column="1" Margin="10,25,10,25" Name="Databit"/>
<ComboBox Grid.Row="3" Grid.Column="1" Margin="10,25,10,25" Name="Stopbit"/>
<ComboBox Grid.Row="4" Grid.Column="1" Margin="10,25,10,25" Name="Parity"/>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="搜索串口" Margin="15,15,15,15"/>
<Button Grid.Row="1" Content="打开串口" Margin="15,15,15,15"/>
<Button Grid.Row="2" Content="发送" Margin="15,15,15,15"/>
</Grid>
<TextBox Grid.Column="1" Margin="10,20,10,20" Name="Revdata"/>
<TextBox Grid.Column="1" Grid.Row="1" Margin="10,20,10,20" Name="Senddata"/>
</Grid>
</Window>
简单的wpf串口代码
于 2024-07-23 15:59:15 首次发布