1, View可以通过DataContext访问ViewModel
除了Binding以外,在一些Event触发的时候,在behind code里用这种方法,直接访问ViewModel。
2, ViewModel访问View
直接设定一个View接口的成员变量,在创建ViewModel的时候,将View设置到该成员变量上。
但这么做不好,(But doing this we would be breaking the sanctity of MVVM.)
3, WPF - Attached behaviors (Closing View from ViewModel)
http://www.shujaat.net/2010/08/attached-behaviors.html
建一个project,copy网页里的代码很容易实现。
简单总结下: (利用附加属性和依赖属性来实现的)