Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Standard Commands - Where's Exit?

Tags:

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.

like image 935
Andrew Shepherd Avatar asked Aug 17 '09 08:08

Andrew Shepherd


People also ask

How do I close a program in WPF?

We can close the window either by using "this. Close()"or by using "App. Current. Shutdown()".

How do I close all windows in WPF?

The proper way to shutdown a WPF app is to use Application. Current. Shutdown() . This will close all open Window s, raise some events so that cleanup code can be run, and it can't be canceled.

What is command binding in WPF?

The command is the action to be executed. The command source is the object which invokes the command. The command target is the object that the command is being executed on. The command binding is the object which maps the command logic to the command.


1 Answers

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.

like image 62
dthrasher Avatar answered Oct 09 '22 12:10

dthrasher