WPF 标准命令 - 退出在哪里? [英] WPF Standard Commands - Where's Exit?
问题描述
我正在我的 WPF 应用程序中创建一个标准菜单.
I'm creating a standard menu in my WPF application.
我知道我可以创建自定义命令,但我知道还有一堆标准命令要绑定.
I know that I can create custom commands, but I know there are also a bunch of standard commands to bind to.
例如,要打开一个文件,我应该绑定到 ApplicationCommands.Open,要关闭一个文件,我应该绑定到 ApplicationCommands.Close.还有大量的EditCommands、ComponentCommands 或NavigationCommands.
For example, to open a file I should bind to ApplicationCommands.Open, to close a file I should bind to ApplicationCommands.Close. There's also a large number of EditCommands, ComponentCommands or NavigationCommands.
似乎没有退出"命令.我本来希望有 ApplicationCommands.Exit.
There doesn't seem to be an "Exit" command. I would have expected there to be ApplicationCommands.Exit.
我应该将什么绑定到退出"菜单项?为这种通用的东西创建自定义命令似乎是错误的.
What should I bind to the "Exit" menu item? To create a custom command for something this generic just seems wrong.
推荐答案
AFAIK 没有 ApplicationCommands.Quit 或 ApplicationCommands.Exit,所以我猜你必须自己创建它...
AFAIK there's no ApplicationCommands.Quit or ApplicationCommands.Exit, so I guess you're gonna have to create it yourself...
无论如何,如果您使用的是 MVVM 模式,RoutedCommands 不是很方便,所以最好使用像 RelayCommand 或 DelegateCommand.
Anyway, if you're using the MVVM pattern, RoutedCommands are not exactly handy, so it's better to use a lightweight alternative like RelayCommand or DelegateCommand.
这篇关于WPF 标准命令 - 退出在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!