-
Notifications
You must be signed in to change notification settings - Fork 678
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
ListView crashes when ISelectionInfo is used with Extended selection #10025
Comments
This bug makes it impossible to use virtualizing ListView with multiple selection. A blocker for my project! Any thoughts on fixing this? |
it looks like something is wrong with the |
@w-ahmad are you saying that the Edit: |
After some experimenting I concluded that most likely the ListView is invalidating the selection iterator by deselecting while iterating. First step was that I changed Second step I compared returning While the exception thrown is not the usual one saying that the iterator has been invalidated, the other symptoms tell the story. The deselection of index 0 changes the Selection list and thereby certainly invalidates any iterator that was obtained earlier. However if a copy of Selection is made then changes to Selection do not invalidate the iterator of that copy. The selection code in ListView should be reviewed and likely fixed so that during deselection it always pulls the first element from the list, or uses a buffer, or otherwise avoids invalidating its iterator. Here is the updated collection code. Switch the commented FAILS/SUCCEEDS lines in GetSelectedRanges and compare the outputs.
|
Describe the bug
An ArgumentOutOfRangeException is thrown when using ListView extended selection with ISelectionInfo.
I originally listed this under #8684 but it would seem to be a separate bug (or reportably separately) since it does not involve a collection changed notification. I guess the root cause could be the same.
Steps to reproduce the bug
Download the WinUI 3 Gallery and compile the WinUiGallery solution.
In ControlPages / ListViewPage.xaml.cs, add "using Microsoft.UI.Xaml.Data;" at the top of the file and add the following collection class at the bottom of the namespace. This is an ObservableCollection implementing ISelectionInfo (not completely, but sufficiently for the demonstration).
Around line 59, change
Control2.ItemsSource = await Contact.GetContactsAsync();
so that it saysControl2.ItemsSource = new ObservableCollectionSelector<Contact>( await Contact.GetContactsAsync());
Run the app, select Collections on the left and then ListView. Scroll down to the second ListView ("ListView with Selection Support") and select Extended as the selection type. Click on the first entry ("Kendal Collins") and then CTRL-Click on the third entry ("Vance DeLeon"). Then release the control key and click on the 5th entry ("Amber Rodriguez").
Expected behavior
Expected: the two previously selected items should be deselected and the new one should be selected. Actual: no change in visual state, and a crash with an ArgumentOutOfRange exception in WinRT.Runtime.dll. If you uncomment the WriteLine statements, it shows that index 0 is deselected then the crash occurs.
The details of the exception are:
Exception thrown: 'System.ArgumentOutOfRangeException' in WinRT.Runtime.dll
Exception thrown at 0x00007FFFC0F6B699 (KernelBase.dll) in WinUIGallery.exe: WinRT originate error - 0x8000000B : 'This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1). (Parameter 'index')'.
Microsoft.ui.xaml.dll!00007FFF23716C7D: 8000000B - E_BOUNDS
Screenshots
No response
NuGet package version
None
Windows version
No response
Additional context
WindowsAppSDK 1.6.240829007 and I happen to be using Windows 10, 22H2 build 19045.4894
The text was updated successfully, but these errors were encountered: