From ff561279be63562314f07d8ba8f418d0e16e5473 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 10 Jun 2015 23:55:10 +0200 Subject: [PATCH] Use Left and Right arrows to open/close submenus. --- Perspex.Controls/MenuItem.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Perspex.Controls/MenuItem.cs b/Perspex.Controls/MenuItem.cs index 4821a02fc1..a8df261c37 100644 --- a/Perspex.Controls/MenuItem.cs +++ b/Perspex.Controls/MenuItem.cs @@ -235,10 +235,32 @@ namespace Perspex.Controls e.Handled = true; } + break; + + case Key.Left: + if (!this.IsTopLevel && this.IsSubMenuOpen) + { + this.IsSubMenuOpen = false; + e.Handled = true; + } + + break; + + case Key.Right: + if (!this.IsTopLevel && this.HasSubMenu && !this.IsSubMenuOpen) + { + this.SelectedIndex = 0; + this.IsSubMenuOpen = true; + e.Handled = true; + } + break; } - if (!((e.Key == Key.Up || e.Key == Key.Down) && !this.IsSubMenuOpen)) + // If this key is a directional key and the submenu isn't open we need the parent + // menu item to handle the keypress, so don't pass the key to the base or it will try + // to move the selection in the non-open submenu. + if (!((e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right) && !this.IsSubMenuOpen)) { base.OnKeyDown(e); }