canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
988 stars 143 forks source link

why window manager ‘s ShowMessageBox can't popup in OnExit method? #149

Closed zredb closed 4 years ago

zredb commented 4 years ago

I want to implement the function when quit the app, program query the user weather save changes, bug these code can't work: protected override void OnExit(ExitEventArgs e) { var wm= kernel.Get(); var dr=wm.ShowMessageBox("Project has change, do you want to save it?","", MessageBoxButton.YesNo); if (dr == MessageBoxResult.Yes) //do something, } can anyone give any sugesstion?

canton7 commented 4 years ago

Perhaps because it's too late and the application is already shutting down? I'm in mobile so can't test.

I recommend overriding CanCloseAsync in your shell ViewModel, and putting your logic in there.

zredb commented 4 years ago

Thank you for your quick reply, I will try to use it, thank you.

canton7 commented 4 years ago

Great. Please re-open if you still have issues.