Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Apparently, this was a deliberate change by Microsoft. See Atanas Koralski's answer here:</p> <p><a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/14f6f49f-0027-471b-b68c-e7f6ba012012" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/14f6f49f-0027-471b-b68c-e7f6ba012012</a></p> <blockquote> <p>Menu and ToolBar mnemonics work without pressing Alt key. We decided that we will have uniform behavior in all cases so access key work without pressing Alt key.</p> <p>I understand that this is not in parity with Forms and we will consider this issue and change the behavior in the next version.</p> <p>For now as a workaround you can register a class handler for all AccessKeyPressed events and handle the event if Alt key is not pressed.</p> <pre><code>EventManager.RegisterClassHandler(typeof(UIElement), AccessKeyManager.AccessKeyPressedEvent, new AccessKeyPressedEventHandler(OnAccessKeyPressed)); </code></pre> <p>...</p> <pre><code>private static void OnAccessKeyPressed(object sender, AccessKeyPressedEventArgs e) { if (!e.Handled &amp;&amp; e.Scope == null &amp;&amp; (e.Target == null || e.Target == label)) { // If Alt key is not pressed - handle the event if ((Keyboard.Modifiers &amp; ModifierKeys.Alt) != ModifierKeys.Alt) { e.Target = null; e.Handled = true; } } } </code></pre> </blockquote> <p>Also see mfc2wpf's reply:</p> <blockquote> <p>I've used the above and it works. However, that prevented the default action for Enter and ESC. So I inserted the following at the top of the method.</p> <pre><code>if (Keyboard.IsKeyDown(Key.Enter) || Keyboard.IsKeyDown(Key.Escape)) return; </code></pre> </blockquote> <p>Access keys include <kbd>Enter</kbd> and <kbd>Esc</kbd>, which are the default keys for <code>Button</code>s which have <code>IsDefault = true</code> or <code>IsCancel = true</code>. If you don't want to require <kbd>Alt</kbd>+<kbd>Enter</kbd> and <kbd>Alt</kbd>+<kbd>Esc</kbd> for those buttons, you would need to add the special condition to the handler.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload