我想知道,假设我做了以下事情:
<Some element Command="{Binding FileButton1}" Content="Load into File1" />
...
<Some element Command="{Binding FileButton2}" Content="Load into File2" />
并且这两个按钮基本上只是将一些文件加载到File1
和File2
变量中。如何实现继电器功能action
的实现,识别哪个按钮被调用?我可以这样做:
FileAddButton1 = new RelayCommand(action, always_true);
FileAddButton2 = new RelayCommand(action, always_true);
然后检查动作方法调用哪个按钮?
提前致谢!
答案 0 :(得分:1)
您可以使用CommandParameter将参数从View发送到Viewmodel。 More information on CommandParameter.
<Some element Command="{Binding FileButton1}"
CommandParameter="MyArgument" Content="Load into File1" />
因此,与您的命令对应的委托将如下所示,
public void OnCommandExecuted(object argument)
{
// argument is the parameter passed from view.
}