1、编写一个Button,绑定后端命令,并传递参数:
<TextBox x:Name="SendMessage" />
<!-- 传递页面中控件的Text -->
<Button
Width="100"
Command="{Binding SendCommand}"
CommandParameter="{Binding ElementName=SendMessage, Path=Text}"
Content="Send" />
2、在ViewModel.cs中编写后端处理代码:
public PortsViewModel()
{
SendCommand = new DelegateCommand<string>(Test);
}
public DelegateCommand<string> SendCommand { get; set; }
public void Test()
{
MessageBox.Show(BaudRate);
}
通过DelegateCommand
来进行参数传递