🎉 数据源展示
This commit is contained in:
parent
4e1d211e40
commit
6fc5ca253e
|
@ -9,4 +9,14 @@
|
|||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.IO.Ports">
|
||||
<HintPath>..\..\..\..\..\..\..\software\Plugins\nuget\system.io.ports\5.0.1\ref\netstandard2.0\System.IO.Ports.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Ports" Version="6.0.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Base_2_Window.MVVM;
|
||||
|
||||
public class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
|
@ -3,17 +3,71 @@
|
|||
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:Base_2_Window"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="5*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock>XXX</TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="0" Width="200" Margin="5">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
|
||||
<Label Width="60" VerticalAlignment="Center">串口:</Label>
|
||||
<ComboBox Width="100" Height="28" ItemsSource="{Binding SerialPortNames}" SelectedIndex="0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
|
||||
<Label Width="60" VerticalAlignment="Center">波特率:</Label>
|
||||
<ComboBox Width="100" Height="28" ItemsSource="{Binding BaudRates}" SelectedIndex="0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
|
||||
<Label Width="60" VerticalAlignment="Center">数据位:</Label>
|
||||
<ComboBox Width="100" Height="28" ItemsSource="{Binding DataBits}" SelectedIndex="0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
|
||||
<Label Width="60" VerticalAlignment="Center">校验位:</Label>
|
||||
<ComboBox Width="100" Height="28" ItemsSource="{Binding ParityList}" SelectedIndex="0" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<Label Width="60" VerticalAlignment="Center">停止位:</Label>
|
||||
<ComboBox Width="100" Height="28" ItemsSource="{Binding StopBitsList}" SelectedIndex="0" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Height="32" Margin="0,5,0,0" FontWeight="Bold" Command="{Binding }">打开串口</Button>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 右侧通信面板 -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 消息显示区域 -->
|
||||
<GroupBox Grid.Row="0" Header="消息显示" Margin="0,0,0,5">
|
||||
<TextBox Name="MessageBox"
|
||||
AcceptsReturn="True"
|
||||
IsReadOnly="True"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
FontFamily="Consolas" />
|
||||
</GroupBox>
|
||||
|
||||
<!-- 消息发送区域 -->
|
||||
<GroupBox Grid.Row="1" Header="发送消息">
|
||||
<DockPanel>
|
||||
<Button DockPanel.Dock="Right"
|
||||
Width="80"
|
||||
Margin="5,0,0,0"
|
||||
FontWeight="Bold">
|
||||
发送
|
||||
</Button>
|
||||
<TextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
|
||||
</DockPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
|
@ -1,23 +1,26 @@
|
|||
using System.Text;
|
||||
using System.IO.Ports;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Base_2_Window.ViewModel;
|
||||
|
||||
namespace Base_2_Window;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = new MainWindowViewModel
|
||||
{
|
||||
SerialPortNames = SerialPort.GetPortNames().Select(s => s).ToList(),
|
||||
BaudRates = new List<int> { 9600 },
|
||||
DataBits = new List<int> { 6, 7, 8 },
|
||||
StopBitsList = new List<StopBits> { StopBits.None, StopBits.One, StopBits.Two, StopBits.OnePointFive },
|
||||
ParityList = new List<Parity>
|
||||
{ Parity.None, Parity.Even, Parity.Mark, Parity.None, Parity.Odd, Parity.Space }
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
using System.IO.Ports;
|
||||
|
||||
namespace Base_2_Window.Model;
|
||||
|
||||
public class SerialPortModel
|
||||
{
|
||||
public List<string>? SerialPortNames { get; set; }
|
||||
|
||||
public int? BaudRate { get; set; }
|
||||
|
||||
public int? DataBits { get; set; }
|
||||
|
||||
public StopBits? StopBits { get; set; }
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using System.IO.Ports;
|
||||
using Base_2_Window.MVVM;
|
||||
|
||||
namespace Base_2_Window.ViewModel;
|
||||
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
public List<string>? SerialPortNames { get; set; }
|
||||
|
||||
public List<int>? BaudRates { get; set; }
|
||||
|
||||
public List<StopBits>? StopBitsList { get; set; }
|
||||
|
||||
public List<Parity>? ParityList { get; set; }
|
||||
|
||||
public List<int>? DataBits { get; set; }
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParity_002Ecs_002Fl_003AC_0021_003FUsers_003F13199_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Feabc9cb4ff56410badff95faf89658e09778_003F32_003F33c960a1_003FParity_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASerialPort_002Ecs_002Fl_003AC_0021_003FUsers_003F13199_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Feabc9cb4ff56410badff95faf89658e09778_003Ff6_003F34911093_003FSerialPort_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStopBits_002Ecs_002Fl_003AC_0021_003FUsers_003F13199_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Feabc9cb4ff56410badff95faf89658e09778_003Fc5_003F355efbd9_003FStopBits_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
Loading…
Reference in New Issue