-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
Exceptions are thrown on all platforms when calling ScrollTo on an unloaded CollectionView (or probably any ItemsView). While it sounds odd to try and scroll an unloaded ItemsView, it can easily happen by accident if ScrollTo is called in an event handler. For example, here is a user project that triggers the bug in a SelectionChanged handler:
SelectionChanged is triggered when removing CollectionView from its parent because the BindingContext changes. When MAUI Full Page Hot Reload in Visual Studio 17.10 reloads the XAML, it can also trigger this issue.
Steps to Reproduce
REPRO:
- Clone test repo:
- https://github.com/spadapet/maui_bugs.git
- Or just copy the test project's directory locally:
- https://github.com/spadapet/maui_bugs/tree/main/ScrollToCrash
- Open the test project solution file in Visual Studio 2022 17.10+
- F5 to build and debug the app on Windows
- Click the button:

RESULT:
App crashes with a NullReferenceException. On Windows, the ItemsViewHandler.Windows.cs file is still listening to scroll requests after CleanUpCollectionViewSource() is called.
On iOS or Android emulator, different exceptions are thrown.
iOS:
An index out of range exception
Link to public reproduction project repository
https://github.com/spadapet/maui_bugs.git
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
No response
Did you find any workaround?
Skip calling ItemsView.ScrollTo if the IsLoaded property is false.
Relevant log output
No response
