WPF MVVM 关闭View

在ViewModel中定义一个变量:

private Action _closeAction;

在ViewModel的构造函数中这样定义:
public MainWindowViewModel(Action closeAction)
{
   this._closeAction=closeAction;
}

在窗体构造函数中:

this.DataContext=new MainWindowViewModel(this.Close);

要关闭时在ViewModel中执行:

this._closeAction.Invoke();

posted on 2015-06-11 19:07  坐看疯云  阅读(278)  评论(0编辑  收藏  举报

导航