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