我试图理解这个概念,但它让我难以理解。
这背后的一般概念是什么?我知道这是可能的,但我并没有完全按照我的研究/自己的测试项目来做到这一点。
我想在我的 View 中不惜一切代价避免代码落后。我想从 View 中解耦诸如“PreviewMouseDown”之类的事件,并让它们触发 ViewModel 中的命令。
谁能给我一些有关如何完成此任务的基本指导?
概括:
查看 (PreviewMouseDown) -> 在 ViewModel (MyPreviewMouseDownCommand) 中调用命令
谢谢
最佳答案
有被否决的风险我认为这不是世界上最糟糕的事情
public void PreviewMouseDown(Object sender, RoutedEventArgs e)
{
var viewModel= (MyViewModel)DataContext;
if (viewModel.MyCommand.CanExecute(null))
viewModel.MyCommand.Execute(null);
}
关于wpf - MouseDown、PreviewMouseDown 等...以及 MVVM 中的 COMMAND 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12270134/