diff --git a/CefSharp.Wpf/WebView.cpp b/CefSharp.Wpf/WebView.cpp index 9fbbc2f909..06c8111829 100644 --- a/CefSharp.Wpf/WebView.cpp +++ b/CefSharp.Wpf/WebView.cpp @@ -226,31 +226,6 @@ namespace Wpf type, mouseUp, e->ClickCount); } - void WebView::OnVisualParentChanged(DependencyObject^ oldParent) - { - EventHandler^ _handler = gcnew EventHandler(this, &WebView::OnHidePopup); - Window^ window; - - if (oldParent != nullptr) - { - window = Window::GetWindow(oldParent); - if (window != nullptr) - { - window->LocationChanged -= _handler; - window->Deactivated -= _handler; - } - } - - window = Window::GetWindow(this); - if (window != nullptr) - { - window->LocationChanged += _handler; - window->Deactivated += _handler; - } - - ContentControl::OnVisualParentChanged(oldParent); - } - Size WebView::ArrangeOverride(Size size) { CefRefPtr browser; @@ -814,10 +789,27 @@ namespace Wpf void WebView::OnLoaded(Object^ sender, RoutedEventArgs^ e) { AddSourceHook(); + + EventHandler^ _handler = gcnew EventHandler(this, &WebView::OnHidePopup); + + currentWindow = Window::GetWindow(this); + if (currentWindow != nullptr) + { + currentWindow->LocationChanged += _handler; + currentWindow->Deactivated += _handler; + } } void WebView::OnUnloaded(Object^ sender, RoutedEventArgs^ e) { + EventHandler^ _handler = gcnew EventHandler(this, &WebView::OnHidePopup); + + if (currentWindow != nullptr) + { + currentWindow->LocationChanged -= _handler; + currentWindow->Deactivated -= _handler; + } + if (_source && _hook) { _source->RemoveHook(_hook); diff --git a/CefSharp.Wpf/WebView.h b/CefSharp.Wpf/WebView.h index 2e9fab377a..74c789d8b3 100644 --- a/CefSharp.Wpf/WebView.h +++ b/CefSharp.Wpf/WebView.h @@ -33,6 +33,7 @@ namespace Wpf BrowserCore^ _browserCore; MCefRefPtr _scriptCore; + Window^ currentWindow; Object^ _sync; HwndSource^ _source; Matrix^ _matrix; @@ -90,7 +91,6 @@ namespace Wpf void AddSourceHook(); protected: - virtual void OnVisualParentChanged(DependencyObject^ oldParent) override; virtual Size ArrangeOverride(Size size) override; virtual void OnGotFocus(RoutedEventArgs^ e) override; virtual void OnLostFocus(RoutedEventArgs^ e) override;