Browse Source

Close menu on escape key.

pull/58/head
Steven Kirk 11 years ago
parent
commit
5c32b5cc42
  1. 1
      Perspex.Controls/Menu.cs
  2. 27
      Perspex.Controls/MenuItem.cs

1
Perspex.Controls/Menu.cs

@ -129,6 +129,7 @@ namespace Perspex.Controls
if (this.IsOpen && e.Key == Key.Escape)
{
this.CloseMenu();
e.Handled = true;
}
}

27
Perspex.Controls/MenuItem.cs

@ -207,9 +207,26 @@ namespace Perspex.Controls
{
base.OnKeyDown(e);
if (this.IsTopLevel && e.Key == Key.Down && this.HasSubMenu)
switch (e.Key)
{
this.IsSubMenuOpen = true;
case Key.Down:
if (this.IsTopLevel && this.HasSubMenu)
{
this.IsSubMenuOpen = true;
this.SelectedIndex = 0;
e.Handled = true;
}
break;
case Key.Escape:
if (this.IsSubMenuOpen)
{
this.IsSubMenuOpen = false;
e.Handled = true;
}
break;
}
}
@ -300,7 +317,6 @@ namespace Perspex.Controls
if (popup != null)
{
popup.PopupRootCreated += this.PopupRootCreated;
popup.Opened += this.PopupOpened;
}
}
@ -338,11 +354,6 @@ namespace Perspex.Controls
}
}
private void PopupOpened(object sender, EventArgs e)
{
this.SelectedIndex = 0;
}
/// <summary>
/// Called when the MenuItem's popup root is opened.
/// </summary>

Loading…
Cancel
Save