Unregister Window::SizeChanged event in TwoPaneView to prevent crashes with C++ apps #2045
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
TwoPaneView crashes with C++ apps if the page hosting the control isn't one currently displayed and if the window is resized (manually, change screen orientation, span/unspan the window, ...)
TwoPaneView registers to "Windows::SizeChanged" events and never unregisters them. After navigation, the instance of TwoPaneView from the first page is destroyed (destructor called), but the event is still registered which will crash the application when the system will try to call the callback method.
This PR simply unregisters Window::SizeChanged event in TwoPaneView's destructor to prevent crashes.
Motivation and Context
Fixes #2044
How Has This Been Tested?
Tested on Windows 10 Desktop and Windows 10X