-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Unregister hooks in ScrollViewerAssist when the ScrollViewer is unloaded #3133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Unregister hooks when the ScrollViewer is unloaded
- Loading branch information
commit 8458eaefe5a21cf30fd792a3e863e67af028658f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for barging in on this code review; I was curious. 😃
This guard is a bit suspicious to me. Why do we only want to listen for the Unloaded event if the
ScrollVieweris not already loaded? I think the situation where it IS loaded is equally relevant. This would be a scenario where the AP is not statically set in XAML, but applied at runtime after theScrollViewerhas loaded. I acknowledge this may not be the most common use case, but it is still possible. In short, I think we should handle both theScrollViewer.IsLoaded=true/falsecases.Another thing to consider is using weak event handlers. Both the
LoadedandUnloadedevent handlers are currently registered as strong event handlers which unregister themselves when the corresponding event fires. However, I think there are scenarios where this will not work - not particularly related to your changes though:If the
ScrollViewerresides in aTabÌtem, it will be loaded and unloaded multiple times when switching between the tabs. The current implementation only seems to wire up the hooks when the AP changes which means it will register for theLoadedevent at startup. However, after navigating away from theTabItemand back to it again, theUnloadedevent will fire, removing the hook, and then there is nothing listening for the "second"Loadedevent to re-register the hook. Perhaps this could be mitigated by simply using weak event handlers and never unregistering them?This comment also applies for the changes to the other AP.
Thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That guard is certainly suspicious! I'm going to step through the code again in the demo app...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolaihenriksen, you're right; this needs to support a variety of scenarios, including:
ScrollViewerwill be loaded and unloaded multiple timesScrollViewerwill be loaded once, unloaded once, and then (hopefully) garbage-collectedScrollViewerhas been loadedI've pushed some changes which should cover all of the above.