Skip to content

Commit

Permalink
Merge pull request #2318 from cwensley/curtis/wpf-fix-mouse-capture-i…
Browse files Browse the repository at this point in the history
…n-parent-panel

Wpf: Fix releasing mouse capture in parent when clicking on a child
  • Loading branch information
cwensley authored Sep 22, 2022
2 parents a5cad53 + c551bce commit e647a6a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/Eto.Wpf/Forms/WpfFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ protected virtual void HandleLostMouseCapture(object sender, swi.MouseEventArgs

protected virtual void HandleMouseDown(object sender, swi.MouseButtonEventArgs e)
{
var args = e.ToEto(ContainerControl);
isMouseCaptured = false;
var args = e.ToEto(ContainerControl);
if (!(Control is swc.Control) && e.ClickCount == 2)
Callback.OnMouseDoubleClick(Widget, args);
if (!args.Handled)
Expand All @@ -862,12 +863,8 @@ protected virtual void HandleMouseDown(object sender, swi.MouseButtonEventArgs e
|| e.Handled
))
{
isMouseCaptured = true;
Control.CaptureMouse();
}
else
{
isMouseCaptured = false;
isMouseCaptured = true;
}
}

Expand Down
40 changes: 36 additions & 4 deletions test/Eto.Test/UnitTests/Forms/Behaviors/MouseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,41 @@ public void EventsFromParentShouldWorkWhenChildRemoved()
Assert.IsTrue(mouseDownInChild, "#3 - MouseUp should NOT be called on child even though it was removed");
Assert.IsFalse(mouseMovedEvenAfterRemoved, "#4 - MouseMoved should NOT be called on child after it was removed");
}



[Test, ManualTest]
public void MouseDownHandledInPanelWithChildShouldReleaseMouseCapture() => ManualForm("Click once on both blue squares,\nthey should both turn green.", form =>
{
StackLayout CreateClickableBox()
{
var child = new Panel
{
BackgroundColor = Colors.Blue,
Size = new Size(40, 40)
};

var parent = new Panel();
parent.Content = child;

parent.MouseDown += (sender, e) =>
{
child.BackgroundColor = child.BackgroundColor == Colors.Blue ? Colors.Green : Colors.Blue;
e.Handled = true;
};

return new StackLayout(parent);
}

var section1 = CreateClickableBox();

var section2 = CreateClickableBox();

return new TableLayout
{
Rows = { section1, section2, null },
Size = new Size(200, 200),
Spacing = new Size(4, 4),
Padding = 8
};
});
}


}

0 comments on commit e647a6a

Please sign in to comment.