Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6fc5ca2

Browse filesBrowse files
committed
🎉 数据源展示
1 parent 4e1d211 commit 6fc5ca2
Copy full SHA for 6fc5ca2

File tree

Expand file treeCollapse file tree

7 files changed

+136
-20
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+136
-20
lines changed

‎CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj

Copy file name to clipboardExpand all lines: CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@
99
<UseWPF>true</UseWPF>
1010
</PropertyGroup>
1111

12+
<ItemGroup>
13+
<Reference Include="System.IO.Ports">
14+
<HintPath>..\..\..\..\..\..\..\software\Plugins\nuget\system.io.ports\5.0.1\ref\netstandard2.0\System.IO.Ports.dll</HintPath>
15+
</Reference>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="System.IO.Ports" Version="6.0.0"/>
20+
</ItemGroup>
21+
1222
</Project>
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Base_2_Window.MVVM;
5+
6+
public class ViewModelBase : INotifyPropertyChanged
7+
{
8+
public event PropertyChangedEventHandler? PropertyChanged;
9+
10+
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
11+
{
12+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
13+
}
14+
}

‎CSharp/SerialPort/Base-2-Window/MainWindow.xaml

Copy file name to clipboardExpand all lines: CSharp/SerialPort/Base-2-Window/MainWindow.xaml
+64-10Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,71 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:local="clr-namespace:Base_2_Window"
76
mc:Ignorable="d"
87
Title="MainWindow" Height="450" Width="800">
98
<Grid>
10-
<Grid.ColumnDefinitions>
11-
<ColumnDefinition></ColumnDefinition>
12-
<ColumnDefinition></ColumnDefinition>
13-
</Grid.ColumnDefinitions>
14-
15-
<StackPanel Grid.Column="0">
16-
<TextBlock>XXX</TextBlock>
17-
</StackPanel>
9+
<Grid.ColumnDefinitions>
10+
<ColumnDefinition Width="2*" />
11+
<ColumnDefinition Width="5*" />
12+
</Grid.ColumnDefinitions>
13+
14+
<StackPanel Grid.Column="0" Width="200" Margin="5">
15+
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
16+
<Label Width="60" VerticalAlignment="Center">串口:</Label>
17+
<ComboBox Width="100" Height="28" ItemsSource="{Binding SerialPortNames}" SelectedIndex="0" />
18+
</StackPanel>
19+
20+
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
21+
<Label Width="60" VerticalAlignment="Center">波特率:</Label>
22+
<ComboBox Width="100" Height="28" ItemsSource="{Binding BaudRates}" SelectedIndex="0" />
23+
</StackPanel>
24+
25+
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
26+
<Label Width="60" VerticalAlignment="Center">数据位:</Label>
27+
<ComboBox Width="100" Height="28" ItemsSource="{Binding DataBits}" SelectedIndex="0" />
28+
</StackPanel>
29+
30+
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
31+
<Label Width="60" VerticalAlignment="Center">校验位:</Label>
32+
<ComboBox Width="100" Height="28" ItemsSource="{Binding ParityList}" SelectedIndex="0" />
33+
</StackPanel>
34+
35+
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
36+
<Label Width="60" VerticalAlignment="Center">停止位:</Label>
37+
<ComboBox Width="100" Height="28" ItemsSource="{Binding StopBitsList}" SelectedIndex="0" />
38+
</StackPanel>
39+
40+
<Button Height="32" Margin="0,5,0,0" FontWeight="Bold" Command="{Binding }">打开串口</Button>
41+
</StackPanel>
42+
43+
<!-- 右侧通信面板 -->
44+
<Grid Grid.Column="1">
45+
<Grid.RowDefinitions>
46+
<RowDefinition Height="*" />
47+
<RowDefinition Height="Auto" />
48+
</Grid.RowDefinitions>
49+
50+
<!-- 消息显示区域 -->
51+
<GroupBox Grid.Row="0" Header="消息显示" Margin="0,0,0,5">
52+
<TextBox Name="MessageBox"
53+
AcceptsReturn="True"
54+
IsReadOnly="True"
55+
VerticalScrollBarVisibility="Auto"
56+
FontFamily="Consolas" />
57+
</GroupBox>
58+
59+
<!-- 消息发送区域 -->
60+
<GroupBox Grid.Row="1" Header="发送消息">
61+
<DockPanel>
62+
<Button DockPanel.Dock="Right"
63+
Width="80"
64+
Margin="5,0,0,0"
65+
FontWeight="Bold">
66+
发送
67+
</Button>
68+
<TextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
69+
</DockPanel>
70+
</GroupBox>
71+
</Grid>
1872
</Grid>
19-
</Window>
73+
</Window>
+13-10Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
using System.Text;
1+
using System.IO.Ports;
22
using System.Windows;
3-
using System.Windows.Controls;
4-
using System.Windows.Data;
5-
using System.Windows.Documents;
6-
using System.Windows.Input;
7-
using System.Windows.Media;
8-
using System.Windows.Media.Imaging;
9-
using System.Windows.Navigation;
10-
using System.Windows.Shapes;
3+
using Base_2_Window.ViewModel;
114

125
namespace Base_2_Window;
136

147
/// <summary>
15-
/// Interaction logic for MainWindow.xaml
8+
/// Interaction logic for MainWindow.xaml
169
/// </summary>
1710
public partial class MainWindow : Window
1811
{
1912
public MainWindow()
2013
{
2114
InitializeComponent();
15+
16+
DataContext = new MainWindowViewModel
17+
{
18+
SerialPortNames = SerialPort.GetPortNames().Select(s => s).ToList(),
19+
BaudRates = new List<int> { 9600 },
20+
DataBits = new List<int> { 6, 7, 8 },
21+
StopBitsList = new List<StopBits> { StopBits.None, StopBits.One, StopBits.Two, StopBits.OnePointFive },
22+
ParityList = new List<Parity>
23+
{ Parity.None, Parity.Even, Parity.Mark, Parity.None, Parity.Odd, Parity.Space }
24+
};
2225
}
2326
}
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.IO.Ports;
2+
3+
namespace Base_2_Window.Model;
4+
5+
public class SerialPortModel
6+
{
7+
public List<string>? SerialPortNames { get; set; }
8+
9+
public int? BaudRate { get; set; }
10+
11+
public int? DataBits { get; set; }
12+
13+
public StopBits? StopBits { get; set; }
14+
}
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.IO.Ports;
2+
using Base_2_Window.MVVM;
3+
4+
namespace Base_2_Window.ViewModel;
5+
6+
public class MainWindowViewModel : ViewModelBase
7+
{
8+
public List<string>? SerialPortNames { get; set; }
9+
10+
public List<int>? BaudRates { get; set; }
11+
12+
public List<StopBits>? StopBitsList { get; set; }
13+
14+
public List<Parity>? ParityList { get; set; }
15+
16+
public List<int>? DataBits { get; set; }
17+
}
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<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">
2+
<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>
3+
<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>
4+
<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>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.