tags:

views:

1219

answers:

3

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.

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.

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.

A: 

AFAIK there's no ApplicationCommands.Quit or ApplicationCommands.Exit, so I guess you're gonna have to create it yourself...

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.

Thomas Levesque
A: 

You can modify the Text property of a command before you bind it in a window. This will change the text of the command everywhere it appears in your ui.

EDIT: Do this to Close in the Window or App ctor

karl.r
+2  A: 

Unfortunately, there is no predefined ApplicationCommands.Exit. Adding one to WPF was suggested on Microsoft Connect in 2008: http://connect.microsoft.com/VisualStudio/feedback/details/354300/add-predefined-wpf-command-applicationcommands-exit. The item has been marked closed/postponed, however.

Mike Taulty discussed how to create your own Exit command in an article on his blog.

dthrasher