【发布时间】:2013-07-20 23:25:16
【问题描述】:
我在我的 WPF 应用程序中使用 MVVMCross,我想提供一个 Close(或 Exit ) 按钮关闭整个应用程序。有没有使用 MVVMCross 功能的简单方法来做到这一点?
我用MainViewModel 尝试了以下方法:
public class MainViewModel : MvxViewModel
{
private MvxCommand _closeCommand;
public MvxCommand CloseCommand {
get {
return _closeCommand ?? (_closeCommand = new MvxCommand(DoClose));
}
}
public void DoClose() {
Close(this);
}
}
不幸的是,无济于事。当我按下一个绑定到CloseCommand 的按钮时,DoClose 方法会被调用,但是视图模型(和相应的视图)无法关闭,即使 WPF App StartupUri 设置为MainView.
【问题讨论】:
-
你试过Application.Current.Shutdown(); ?
-
谢谢,@Nitesh。但是,理想情况下,我想在可移植视图模型中管理应用程序关闭。
Application.Current.Shutdown在 PCL“核心”项目中不可用。 -
好的,那么我也想得到这个问题的答案。