Repository navigation
[NET 11][Windows] Fix CollectionView crashes when multiple CollectionViews share the same ObservableCollection - #39760
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39760Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39760" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| items.Add("Item 4"); | ||
| handler.PlatformView.UpdateLayout(); | ||
| await Task.Delay(100); | ||
|
|
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - The visible CollectionView does not provide a discriminating negative test for the new visibility guard: its only assertions compare ItemsSource contents, which are updated independently of ApplyItemsUpdatingScrollMode. The reveal assertions likewise check loaded labels rather than scrolling, and the fixture starts with only three 40px rows in a 200px viewport. Returning unconditionally from ApplyItemsUpdatingScrollMode would still satisfy these assertions, while breaking automatic scrolling for visible views. Add an overflowing visible-view case and assert the resulting scroll position for both modes (starting away from the first item for KeepItemsInView), so the test proves that visible updates are not suppressed along with hidden ones.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetests
🧪 maui-pr-uitests
🧭 Follow-up — actions and refreshNext action: Restore evidence; inspect device termination and CV1 snapshot packaging. Do not duplicate existing runs.
|
There was a problem hiding this comment.
🔵 Needs a closer look
Windows runtime validation remains necessary because deferred scroll callbacks recheck only IsLoaded after visibility may change, and the added device tests were not executed.
No open issues 🎉
What changed in this PR
Addresses #39751, a .NET 11 Windows CollectionView regression where updating a shared ObservableCollection can crash when one bound view is hidden. The fix guards automatic scrolling in the Items2 handler.
Changes:
- Skip item-update scrolling when the native view is collapsed, even if it reports being loaded.
- Add Windows device tests covering shared-source updates, visibility transitions, collection mutations, and both supported automatic-scroll modes.
| File | Description |
|---|---|
| src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Windows.cs | Adds regression coverage for visible and hidden CollectionViews sharing a collection. |
| src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs | Adds a native visibility check before automatic scrolling. |
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 📱 Device tests
Execution log excerptsWithout fix With fix PR head: bf5052d9. Without-fix baseline: 7de2a9f2. |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details:
On Windows, the application crashes when multiple CollectionView controls share the same ObservableCollection and one of the views is hidden.
The issue can be reproduced by binding two CollectionView controls to the same ObservableCollection, setting IsVisible to false on one of them, and then adding a new item to the collection.
Root Cause:
Collection changes trigger automatic scrolling. A collapsed WinUI view can still report IsLoaded == true without having its internal item presenter created. The previous loaded-state check therefore allowed an invalid native scroll request.
Description of Changes:
Skip scrolling related logic when the native view is collapsed
Issues Fixed
Fixes #39751
Tested the behavior in the following platforms.
Before-39751.mp4
After-39751.mp4