diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index ca47a130a..38efb4952 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -470,8 +470,8 @@ namespace CefSharp.Wpf if(popup != null) { - popup.MouseEnter -= PopupMouseEnter; - popup.MouseLeave -= PopupMouseLeave; + popup.Opened -= PopupOpened; + popup.Closed -= PopupClosed; popup = null; } @@ -1639,8 +1639,8 @@ namespace CefSharp.Wpf Placement = PlacementMode.Absolute, }; - newPopup.MouseEnter += PopupMouseEnter; - newPopup.MouseLeave += PopupMouseLeave; + newPopup.Opened += PopupOpened; + newPopup.Closed += PopupClosed; return newPopup; } @@ -1904,24 +1904,29 @@ namespace CefSharp.Wpf } /// - /// Handle the mouse cursor entering the pop-up. + /// Captures the mouse when the popup is opened. /// /// The sender. - /// The instance containing the event data. - private void PopupMouseEnter(object sender, MouseEventArgs e) + /// The instance containing the event data. + private void PopupOpened(object sender, EventArgs e) { - Focus(); - Mouse.Capture(this, CaptureMode.Element); + if (Mouse.Captured != this) + { + Mouse.Capture(this); + } } /// - /// Handle the mouse cursor exiting the pop-up. + /// Releases mouse capture when the popup is closed. /// /// The sender. - /// The instance containing the event data. - private void PopupMouseLeave(object sender, MouseEventArgs e) + /// The instance containing the event data. + private void PopupClosed(object sender, EventArgs e) { - Mouse.Capture(this, CaptureMode.None); + if (Mouse.Captured == this) + { + Mouse.Capture(null); + } } /// @@ -1934,7 +1939,6 @@ namespace CefSharp.Wpf { Focus(); OnMouseButton(e); - Mouse.Capture(this); } /// @@ -1944,7 +1948,6 @@ namespace CefSharp.Wpf protected override void OnMouseUp(MouseButtonEventArgs e) { OnMouseButton(e); - Mouse.Capture(null); } ///