Open spadapet opened 5 months ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
CollectionView
throws NRE when ScrollTo
method is called from a handler of event Window.Created
(#17865), similarity score: 0.79Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Verified this issue with Visual Studio 17.11.0 Preview 2.0 (8.0.40 & 8.0.21 & 8.0.3). Can repro this issue with sample project.
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:
https://github.com/YBTopaz8/Dimmer-MAUI/blob/f5366d12d8a59a0d70ce80b201891a672d0cd13d/Dimmer/Views/Desktop/HomeD.xaml.cs#L32
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:
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.
Android:
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