Application.Current.MainWindow.Close 与 Application.Current.Shutdown [英] Application.Current.MainWindow.Close vs Application.Current.Shutdown

查看:41
本文介绍了Application.Current.MainWindow.Close 与 Application.Current.Shutdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不应该将 Application.Current.Shutdown() 用作关闭 WPF 应用程序的最佳做法吗?

Should Application.Current.Shutdown() NOT be used as a best practice to close a WPF application?

我有一个小的多窗口应用程序,关闭"似乎对我所有的退出命令都很好.但是,有人告诉我总是使用 Application.Current.MainWindow.Close().

I have a small, multiple window application and the "shutdown" seems to work nicely for all my exit commands. However, I have been told to always use Application.Current.MainWindow.Close().

推荐答案

MainWindow.Close 如果 ShutdownMode 未分别设置.你可以做你想做的,它应该符合人们期望.

(Shutdown 将忽略某些 Closing 事件被取消的事实,因此这是您需要考虑的一件事)

(Shutdown will ignore the fact that some Closing event was cancelled, so that would be one thing you need to take into consideration)

还有:

Windows Presentation Foundation (WPF) 在以下情况下隐式调用关闭:

Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations:

  • 当 ShutdownMode 设置为 OnLastWindowClose 时.

  • When ShutdownMode is set to OnLastWindowClose.

当 ShutdownMode 设置为 OnMainWindowClose 时.

When the ShutdownMode is set to OnMainWindowClose.

当用户结束会话并且 SessionEnding 事件未处理或未取消处理时.

When a user ends a session and the SessionEnding event is either unhandled, or handled without cancellation.

这篇关于Application.Current.MainWindow.Close 与 Application.Current.Shutdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆