WPF页面向后端传参

WPF页面(前端)向后端传参

1、编写一个Button,绑定后端命令,并传递参数:

csharp 复制代码
<Button
	Width="100"
	Command="{Binding SendCommand}"
	CommandParameter="{Binding ElementName=SendMessage, Path=Text}"
	 Content="Send" />

2、在ViewModel.cs中编写后端处理代码:

csharp 复制代码
public PortsViewModel()
{
	SendCommand = new DelegateCommand<string>(Test);
}
public DelegateCommand<string> SendCommand { get; set; }
public void Test()
{
	MessageBox.Show(BaudRate);
}

通过DelegateCommand<T>来进行参数传递

相关推荐
故事不长丨12 小时前
C#委托的使用
c#·wpf·winfrom·委托·网站开发
行走正道15 小时前
【探索实战】跨云应用分发自动化实战:基于Kurator的统一交付体系深度解析
运维·自动化·wpf·kurator·跨云分发
Macbethad19 小时前
基于WPF的Ethernet/IP主站程序技术方案
网络协议·tcp/ip·wpf
张人玉1 天前
Prism Template Pack 完整使用示例(VS2022 + .NET 8 + DryIoc)
.net·wpf·prism
棉晗榜1 天前
wpf 在XAML中配置视图模型,通过 d:DataContext设置设计时类型,方便按F12跳转查看类型
wpf
赵财猫._.1 天前
HarmonyOS渲染性能优化:组件树复用与局部刷新机制
wpf·harmonyos·ux
赵财猫._.1 天前
鸿蒙分布式数据库同步:冲突解决与数据一致性策略
wpf·harmonyos·ux
Macbethad2 天前
使用WPF编写一个数据记录页面
wpf
dotent·4 天前
C#基于WPF UI框架的通用基础上位机测试WPF框架
ui·c#·wpf
咩图5 天前
WPF+Prism8.0.0.1909+C#创建一个桌面程序
c#·wpf·prism