在应用 Command 模式中,需要在View上点击 一个按钮,需要将当前窗体作为参数传递为 command
两种方式传递当前窗体
1、通过窗体名称(假设窗体名称为 ThisWindow)
2、绑定到 RelativeSource
-------------------------------------------------------------------------------------------------------------------
以下是ViewModel中的 Command 代码
private DelegateCommand_cancelCommand = null; public DelegateCommand CancelCommand { get { if (_cancelCommand == null) { _cancelCommand = new DelegateCommand (Cancel); } return _cancelCommand; } } void Cancel(Window window) { if (window != null) { window.DialogResult = false; window.Close(); } }
转载自:https://blog.csdn.net/kw269937519/article/details/108510398
参考网址:http://stackoverflow.com/questions/3504332/passing-the-current-window-as-a-commandparameter



