ALT+F4 and the IsCancel button

Topics: Prism v2 - WPF 4
Nov 25, 2010 at 10:06 AM

Is it possible to have Alt+F4 (as well as the X close button + <system menu> :: Close) trigger the button (and thus its command) that is marked as "IsCancel"? I'd like to have it behave in the same way to pressing the Escape key.

Note: The dialog is being creating in a RegionBehavior so I cannot directly access the button

Nov 25, 2010 at 3:50 PM
Edited Nov 25, 2010 at 3:51 PM

Hi,

There is no guidance on this topic in Prism out-of-the box. But I think that you can find the following documentation section on MSDN:

The Register method in the AccessKeyManager class allows you to associate a specified access key (ALT+F4) with the specified element (Button). But it requires you to extend the dialog.

Another possible approach is to create a Global Command. For more information, you could take a look at the following documentation section on MSDN: How to: Create Globally Available Commands. Then you could add a handler for the KeyDown event and call your GlobalCommand.

Hope this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero