Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8172 from AvaloniaUI/make-menu-selectio…
Browse files Browse the repository at this point in the history
…n-logic-consistant-with-other-frameworks

Fix Menu selection to match UWP.
# Conflicts:
#	src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  • Loading branch information
danwalmsley committed Jun 1, 2022
1 parent 7c1fc90 commit 761edc1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public virtual void Attach(IMenu menu)
Menu.AddHandler(Avalonia.Controls.Menu.MenuOpenedEvent, this.MenuOpened);
Menu.AddHandler(MenuItem.PointerEnterItemEvent, PointerEnter);
Menu.AddHandler(MenuItem.PointerLeaveItemEvent, PointerLeave);
Menu.AddHandler(InputElement.PointerMovedEvent, PointerMoved);

_root = Menu.VisualRoot;

Expand Down Expand Up @@ -90,6 +91,7 @@ public virtual void Detach(IMenu menu)
Menu.RemoveHandler(Avalonia.Controls.Menu.MenuOpenedEvent, this.MenuOpened);
Menu.RemoveHandler(MenuItem.PointerEnterItemEvent, PointerEnter);
Menu.RemoveHandler(MenuItem.PointerLeaveItemEvent, PointerLeave);
Menu.RemoveHandler(InputElement.PointerMovedEvent, PointerMoved);

if (_root is InputElement inputRoot)
{
Expand Down Expand Up @@ -333,7 +335,23 @@ protected internal virtual void PointerEnter(object sender, PointerEventArgs e)
}
}

protected internal virtual void PointerLeave(object sender, PointerEventArgs e)
protected internal virtual void PointerMoved(object? sender, PointerEventArgs e)
{
// HACK: #8179 needs to be addressed to correctly implement it in the PointerPressed method.
var item = GetMenuItem(e.Source as IControl) as MenuItem;
if (item?.TransformedBounds == null)
{
return;
}
var point = e.GetCurrentPoint(null);

if (point.Properties.IsLeftButtonPressed && item.TransformedBounds.Value.Contains(point.Position) == false)
{
e.Pointer.Capture(null);
}
}

protected internal virtual void PointerLeave(object? sender, PointerEventArgs e)
{
var item = GetMenuItem(e.Source as IControl);

Expand Down

0 comments on commit 761edc1

Please sign in to comment.