/// <summary> /// This is the method that responds to the KeyDown event. /// </summary> /// <param name="e">Event arguments</param> protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); Key key = e.Key; switch (key) { case Key.Escape: { if (CurrentSelection != null && CurrentSelection.IsSubmenuOpen) { CurrentSelection.SetCurrentValueInternal(MenuItem.IsSubmenuOpenProperty, BooleanBoxes.FalseBox); OpenOnMouseEnter = false; e.Handled = true; } else { KeyboardLeaveMenuMode(); e.Handled = true; } } break; case Key.System: if ((e.SystemKey == Key.LeftAlt) || (e.SystemKey == Key.RightAlt) || (e.SystemKey == Key.F10)) { KeyboardLeaveMenuMode(); e.Handled = true; } break; } }