diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index c7a72af083..49b81a9920 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -83,7 +83,6 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow /// private int disposeCount; /// - /// /// Location of the control on the screen, relative to Top/Left /// Used to calculate GetScreenPoint /// We're unable to call PointToScreen directly due to treading restrictions @@ -1547,6 +1546,8 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA window.StateChanged += WindowStateChanged; window.LocationChanged += OnWindowLocationChanged; } + + updateBrowserScreenLocation(); } } else if (args.OldSource != null) @@ -1588,11 +1589,19 @@ private void WindowStateChanged(object sender, EventArgs e) } } + private void updateBrowserScreenLocation() + { + if (PresentationSource.FromVisual(this) != null) + { + browserScreenLocation = PointToScreen(new Point()); + } + } + private void OnWindowLocationChanged(object sender, EventArgs e) { //We maintain a manual reference to the controls screen location //(relative to top/left of the screen) - browserScreenLocation = PointToScreen(new Point()); + updateBrowserScreenLocation(); } /// @@ -1743,7 +1752,7 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) tooltipTimer.IsEnabled = false; //Initial value for screen location - browserScreenLocation = PointToScreen(new Point()); + updateBrowserScreenLocation(); } ///