如果您询问任何事件如何适合 MVVM,那么您必须记住 MVVM 是关于抽象View
的ViewModel
,Model
即View
不知道它ViewModel
是什么以及底层Model
是什么。
所以坚持这个想法,有2个观点。
1. If a view based event is handled in the code behind of the view (such as in `MyView.xaml.cs`) then as long as it does not refer the model or the viewmodel, it is perfectly fine in MVVM. Because such event handler is strictly a `View` specific code and should remain confined in the View layer (XAML or XAML.CS).
2. If an event handler has to refer the model or the viewmodel then it should not be handled in the code behind of the view but should be converted into `Command` based behavior using Attached Properties.
对于您的拖放场景,我更喜欢第 2 种方式。Google 获取附加属性和 MVVM wrt 事件,您会找到很好的示例。