Fix for Escape key on dropdown button's popup

Dec 11, 2012 at 8:07 PM
Edited Dec 11, 2012 at 8:09 PM

Escape key on dropdow button's popup is broken in metro window.

Here is my fix. In \Fluent\DropDownButton.cs Replace OnDropDownOpened() {} with the code below:

        // Handles drop down opened
        private void OnDropDownOpened()
        {
            // esri. dissmiss at Escape key
            focusedElement = Keyboard.FocusedElement;
            System.Diagnostics.Debug.WriteLine("Focused element - " + focusedElement);
            if (focusedElement != null)
            {
              focusedElement.LostKeyboardFocus += OnFocusedElementLostKeyboardFocus;
              focusedElement.PreviewKeyDown += OnFocusedElementPreviewKeyDown;
            }
            if (this.DropDownOpened != null)
            {
                this.DropDownOpened(this, EventArgs.Empty);
            }
        }
        private void OnFocusedElementPreviewKeyDown(object sender, KeyEventArgs e)
        {
          // esri. dissmiss at Escape key
          if (e.Key == Key.Escape) IsDropDownOpen = false;
        }

        private void OnFocusedElementLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
          // esri. dissmiss at Escape key
          focusedElement.LostKeyboardFocus -= OnFocusedElementLostKeyboardFocus;
          focusedElement.PreviewKeyDown -= OnFocusedElementPreviewKeyDown;
        }

 

This should also fix Escape key on menus.


Developer
Jul 25, 2013 at 10:17 PM
Marked as answer by batzen on 6/28/2014 at 2:15 AM