Fix ListBox crash when scrolling after item removal - #21838
Merged
MrJul merged 2 commits intoJul 24, 2026
Merged
Conversation
NathanDrake2406
marked this pull request as ready for review
July 23, 2026 16:27
|
You can test this PR using the following package version. |
MrJul
pushed a commit
that referenced
this pull request
Jul 29, 2026
* Add regression test for ListBox removal scroll crash * Fix virtualized arrange after collection changes
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does the pull request do?
Prevents
VirtualizingStackPanelfrom arranging realized containers at aNaNposition whileScrollIntoViewis waiting for a viewport update. This fixes the deterministicListBoxcrash reported in #20085.What is the current behavior?
After scrolling a virtualized
ListBoxto its end, removing an item before the realized range marks that range's stored start position as unstable. CallingScrollIntoView(0)then intentionally defers measure until the effective viewport changes, but the intervening arrange consumes the unstableNaNposition and throwsInvalidOperationException: Invalid Arrange rectangle.What is the updated/expected behavior with this PR?
The transitional arrange uses the panel's existing element-position estimator when the realized range has an unstable start position. Once the viewport update arrives, the normal measure pass replaces the estimate with the exact position. The list can scroll back to the new first item without throwing.
Validation on macOS ARM64 with .NET 10:
Removing_First_Item_After_Scrolling_To_End_Should_Allow_Scrolling_To_Start, which reproduced the exception before the fix and verifies the new first item after scrolling.ListBoxVirtualizationIssueTests: 6 passed, 0 failed.VirtualizingStackPanelTests: 130 passed, 0 failed.Avalonia.Controls.UnitTestsexecutable: 3,648 passed, 1 existing intentional skip, 0 failed.How was the solution implemented (if it's not obvious)?
RealizedStackElements.StartUdeliberately returnsNaNwhen collection changes make the cached position unreliable.ArrangeOverridenow recognizes that sentinel and obtains a finite transitional position throughGetOrEstimateElementU, the same estimator already used when positioning unrealized and focused elements.The commits follow the repository's bug-fix convention: the first commit adds the failing behavioral test, and the second commit contains the fix.
Checklist
Breaking changes
None. The change only replaces an invalid transitional arrange coordinate with the panel's existing estimate.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #20085