I’m interested in creating commands that are available from anywhere in my WPF application.
I’d like them to work in the same way as Cut, Copy, Paste and the other Application level commands, ie:
<Button Command="Paste" />
I assumed I could setup CommandBindings for the Application instance, but that property isn’t available.
How is this done?
The best I have managed so far is to create a suite of commands on the top level window and then access them like this…:
<Button Command="{x:Static namespace::MainWindow.CommandName}" />
Which works, but is of course tightly coupled, and so extremely brittle.
You can setup CommandBindings for “All Windows” of your WPF application and implement command handlers in Application class.
First of all, create a static command container class. For example,
Next, set your custom command to Button.Command like this.
Finally, implement the command handler of your custom command in Application class.