Assigning Keyboard Shortcut / Access Keys to your WPF Application

Assigning shortcut/access keys to say a button (So instead of click on the Next Button you can press N on your keyboard) is something really trivial in a the Windows Form's world - but strangely in WPF the friendly '&' that you place in front of the Char of your Windows Forms Text property fails to work. At least at the time of writing this post all major search engines seems to return minimal information on how to set an access key for a button.

As it turns out in WPF you need to use the _ (underscore) char instead of a & to assign a shortcut key. Thanks to a colleague of mine who pointed out the reason for it being that using a '&' in XAML would require typing &amp due to XML syntax.

Rob Relyea and a few others from the VS 2008 Designer and Blend team discussed on an internal alias as to how to make it easier for developers moving from the Windows Forms/Visual Basic world to be made aware of this change. If you do have any suggestions do drop a comment below or you can also leave a comment on Rob's blog post on this topic here.