我使用MVVMCross我WPF應用,我想提供一個關閉(或退出)在GUI按鈕來關機整個應用程序。有沒有一種簡單的方法來使用MVVMCross功能?如何在MVVMCross WPF應用程序中實現關閉按鈕?
我曾嘗試以下方法與我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
謝謝@Nitesh。理想情況下,我想在便攜式視圖模型中管理應用程序關閉。 'Application.Current.Shutdown'在PCL「核心」項目中不可用。 –
好,那麼我想也得到一個問題的答案。 – Nitesh