如何从上下文菜单关闭 WPF 应用程序?
WPF 中是否有用于从上下文菜单关闭应用程序的命令?也就是说,右键单击任何窗口的标题栏所获得的上下文菜单相同吗?
有很多标准命令,但我正在努力寻找退出命令。
Is there a command in WPF to close the application from context menu? That is, the same context menu which you get by right clicking on the title bar on any window?
There are loads of standard commands, but I am struggling to find an exit command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,这并不存在。您必须实现自定义命令并调用
Unfortunately this doesn't exist. You'll have to implement a custom command and call
有一个ApplicationCommands.Close,但没有一个ApplicationCommands.Exit。
请参阅此线程(例如)以查找替代方案(例如创建自定义命令) 。
There is an ApplicationCommands.Close, but there is not an ApplicationCommands.Exit.
See this thread (for example) to find alternatives (such as creating a custom command).
你的问题已经解决了。但以下代码可能对其他人有帮助。
Your problem is solved. But following code may help others.
实际上并没有那么复杂(但是,M$ 不提供它仍然很糟糕)。给你:
并且甚至可能不需要
AplicationCloseCommand.CanExecuteChanged
事件处理程序的主体。你可以像这样使用它:
干杯!
(你无法想象我自己花了多长时间才发现这个命令的东西......)
Not that complex actually (but still, M$ sucks for not providing it). Here you go:
And the body of the
AplicationCloseCommand.CanExecuteChanged
event handler may not be even needed.You use it like so:
Cheers!
(You cannot imagine how long it took me to discover this Command stuff myself...)