Browse Source

Menu interaction handler fixes.

pull/4795/head
Dariusz Komosiński 6 years ago
parent
commit
858b78b59e
  1. 4
      src/Avalonia.Controls/MenuItem.cs
  2. 18
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

4
src/Avalonia.Controls/MenuItem.cs

@ -101,7 +101,7 @@ namespace Avalonia.Controls
private ICommand? _command;
private bool _commandCanExecute = true;
private Popup _popup;
private Popup? _popup;
/// <summary>
/// Initializes static members of the <see cref="MenuItem"/> class.
@ -145,7 +145,7 @@ namespace Avalonia.Controls
{
var parent = x as Control;
return parent?.GetObservable(DefinitionBase.PrivateSharedSizeScopeProperty) ??
Observable.Return<DefinitionBase.SharedSizeScope>(null);
Observable.Return<DefinitionBase.SharedSizeScope?>(null);
});
this.Bind(DefinitionBase.PrivateSharedSizeScopeProperty, parentSharedSizeScope);

18
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -148,6 +148,7 @@ namespace Avalonia.Controls.Platform
{
case Key.Up:
case Key.Down:
{
if (item?.IsTopLevel == true)
{
if (item.HasSubMenu && !item.IsSubMenuOpen)
@ -161,8 +162,10 @@ namespace Avalonia.Controls.Platform
goto default;
}
break;
}
case Key.Left:
{
if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen)
{
parent.Close();
@ -174,8 +177,10 @@ namespace Avalonia.Controls.Platform
goto default;
}
break;
}
case Key.Right:
{
if (item != null && !item.IsTopLevel && item.HasSubMenu)
{
Open(item, true);
@ -186,8 +191,10 @@ namespace Avalonia.Controls.Platform
goto default;
}
break;
}
case Key.Enter:
{
if (item != null)
{
if (!item.HasSubMenu)
@ -202,12 +209,14 @@ namespace Avalonia.Controls.Platform
e.Handled = true;
}
break;
}
case Key.Escape:
if (item?.Parent != null)
{
if (item?.Parent is IMenuElement parent)
{
item.Parent.Close();
item.Parent.Focus();
parent.Close();
parent.Focus();
}
else
{
@ -216,8 +225,10 @@ namespace Avalonia.Controls.Platform
e.Handled = true;
break;
}
default:
{
var direction = e.Key.ToNavigationDirection();
if (direction.HasValue)
@ -246,6 +257,7 @@ namespace Avalonia.Controls.Platform
}
break;
}
}
if (!e.Handled && item?.Parent is IMenuItem parentItem)

Loading…
Cancel
Save