ataranto / CefSharp

.Net binding for the Chromium Embedded Framework
Other
62 stars 34 forks source link

Move the subscription to LocationChanged and Deactivated Window events to OnLoaded. #62

Open KristinaKoeva opened 11 years ago

KristinaKoeva commented 11 years ago

When you have one single WPF Window and its Content is a WebView, you could simulate reloading of the WebView, by disposing the old one and creating a new one. This causes the OnVisualParentChanged to execute two times, for the old and new WebView. The Window is the same so the following code,
window->LocationChanged += _handler; window->Deactivated += _handler; executes two times. When the location of the Window changes the handler for the old, disposed view is invoked, which is incorrect and causes exceptions.

KristinaKoeva commented 11 years ago

Hey,

Unfortunately there are still few cases when Window::GetWindow(oldParent) returns null. The last commit stores the window reference, so that we could use it to unsubscribe from the events.