Skip to content

Commit

Permalink
Merge pull request #2308 from cwensley/curtis/wpf-mouseup-when-lost-m…
Browse files Browse the repository at this point in the history
…ouse-capture

Wpf: Fire MouseUp when a control loses mouse capture
  • Loading branch information
cwensley authored Sep 12, 2022
2 parents 8dbe618 + 0dcdc90 commit 31a4342
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Eto.Wpf/Forms/WpfFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public override void AttachEvent(string id)
ContainerControl.PreviewMouseDown += HandleMouseDown;
else
ContainerControl.MouseDown += HandleMouseDown;
ContainerControl.LostMouseCapture += HandleLostMouseCapture;
HandleEvent(Eto.Forms.Control.MouseUpEvent);
break;
case Eto.Forms.Control.MouseDoubleClickEvent:
Expand Down Expand Up @@ -811,10 +812,11 @@ void HandleMouseMove(object sender, swi.MouseEventArgs e)
protected virtual void HandleMouseUp(object sender, swi.MouseButtonEventArgs e)
{
var args = e.ToEto(ContainerControl, swi.MouseButtonState.Released);
if (isMouseCaptured && Control.IsMouseCaptured)
if (isMouseCaptured)
{
Control.ReleaseMouseCapture();
isMouseCaptured = false;
if (Control.IsMouseCaptured)
Control.ReleaseMouseCapture();
}

Callback.OnMouseUp(Widget, args);
Expand All @@ -827,6 +829,19 @@ void HandleMouseDoubleClick(object sender, swi.MouseButtonEventArgs e)
Callback.OnMouseDoubleClick(Widget, args);
e.Handled = args.Handled;
}

protected virtual void HandleLostMouseCapture(object sender, swi.MouseEventArgs e)
{
if (isMouseCaptured)
{
// lost mouse capture without a MouseUp event firing
// this can happen when something happens during the mouse dragging, such as showing a dialog.
isMouseCaptured = false;

var args = e.ToEto(ContainerControl, swi.MouseButtonState.Released);
Callback.OnMouseUp(Widget, args);
}
}

protected virtual void HandleMouseDown(object sender, swi.MouseButtonEventArgs e)
{
Expand Down

0 comments on commit 31a4342

Please sign in to comment.