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>来进行参数传递

相关推荐
hqwest17 小时前
C#WPF实战出真汁07--【系统设置】--菜品类型设置
开发语言·c#·wpf·grid设计·stackpanel布局
hqwest1 天前
C#WPF实战出真汁08--【消费开单】--餐桌面板展示
c#·wpf·ui设计·wpf界面设计
orangapple1 天前
WPF 打印报告图片大小的自适应(含完整示例与详解)
c#·wpf
三千道应用题2 天前
WPF&C#超市管理系统(6)订单详情、顾客注册、商品销售排行查询和库存提示、LiveChat报表
开发语言·c#·wpf
✎ ﹏梦醒͜ღ҉繁华落℘3 天前
开发WPF项目时遇到的问题总结
wpf
hqwest4 天前
C#WPF实战出真汁06--【系统设置】--餐桌类型设置
c#·.net·wpf·布局·分页·命令·viewmodel
Vae_Mars4 天前
WPF中使用InputBindings进行快捷键绑定
wpf
hqwest4 天前
C#WPF实战出真汁05--左侧导航
开发语言·c#·wpf·主界面·窗体设计·视图viewmodel
hqwest4 天前
C#WPF实战出真汁01--项目介绍
开发语言·c#·wpf
wuty0075 天前
WPF 实现支持动态调整高度的文本显示控件
wpf·scrollviewer·extentheight·自动高度控件·动态调整高度