Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当用户关闭我的应用程序时,如果他们有未保存的更改,我希望能够提示他们确认,如果他们指示这样做,则取消应用程序的关闭。应用程序的退出事件不允许取消。有没有办法做到这一点?
改为捕获 MainWindow 的 Closing 事件:
App.Current.MainWindow.Closing += MainWindow_Closing;
然后,如有必要,您可以在事件处理程序中将 Cancel 属性设置为 true:
private void MainWindow_Closing(object sender, System.ComponentModel.ClosingEventArgs e) { e.Cancel = true; }
希望这可以帮助...
克里斯