Repository navigation
[Windows] Fix grouped CollectionView item display in CollectionViewHandler2 - #40607
Conversation
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.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
The new screenshot assertion lacks required baseline images, so the test will fail even when grouped items render correctly.
1 open issue
What changed in this PR
Fixes grouped CollectionView rendering after source resets or navigation on Windows by allowing CollectionViewHandler2 to recreate disconnected item views.
Changes:
- Clears stale wrapper content after automatic handler disconnection.
- Removes size and unload observers during cleanup and protects current observers from late unload events.
- Adds a grouped CollectionView reproduction page and a navigation regression test.
| File | Description |
|---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue40414.cs |
Adds flyout navigation and screenshot verification. |
src/Controls/tests/TestCases.HostApp/Issues/Issue40414.cs |
Adds grouped content that resets its source on appearance. |
src/Controls/src/Core/Handlers/Items2/Windows/ItemFactory.cs |
Tightens size and unload observer cleanup. |
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs |
Clears disconnected native content so wrappers can recreate it. |
Review effort: Balanced
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.
There was a problem hiding this comment.
Expert Review — 2 findings
Reviewed commit bca604d.
Previously reported findings were not duplicated.
kubaflo
left a comment
There was a problem hiding this comment.
Could you please check the failed tests?
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 2 findings
Reviewed commit 41848ba.
See inline comments for details.
Previously reported findings were not duplicated.
kubaflo
left a comment
There was a problem hiding this comment.
Ui tests are failing. Please don't comment /azp run maui-pr-uitests, and maui-pr-devicetests. You can do /review run-tests
This comment has been minimized.
This comment has been minimized.
MAUI Autopilot — StartedModels
Info
|
|
MAUI Autopilot · round 1 The fix was committed locally but not published: the follow-up PR exceeded the publishing tool’s patch-size limit. The review threads remain open. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| App.TapInShellFlyout("Flyout2Content"); | ||
| App.WaitForElement("GroupedCollectionView"); | ||
|
|
||
| VerifyScreenshot(retryTimeout: TimeSpan.FromSeconds(2)); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - The added baselines still omit two enabled configurations: snapshots/windows-cv1 and snapshots/ios. The CollectionView shard runs in the Windows CV1 lane with UseWindowsCV1:true and in the iOS 18.4 lane (eng/pipelines/common/ui-tests.yml and eng/pipelines/ui-tests.yml). VerifyScreenshot() selects windows-cv1 and ios respectively, and VisualRegressionTester requires that exact directory without falling back to windows or ios-26. These configurations therefore fail with a missing baseline even when the grouped items render correctly. Add GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage.png for both configurations, or replace the screenshot assertion with rendered-content assertions.
| _observedContent = null; | ||
|
|
||
| // A late unload from replaced content must not clear the current observer. | ||
| if (ReferenceEquals(_observedContent, sender)) |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No discriminating test protects this stale-sender guard or the replacement observer's lifecycle. Issue40414 uses MeasureAllItems and static labels, so its screenshot cannot verify that replacement size growth updates the MeasureFirstItem cache. Existing reattachment and source-swap tests also do not deliver an old content element's Unloaded callback after installing a replacement observer. Add a focused Windows test for that ordering, assert that the replacement remains tracked and updates the cache on growth, then recycle it and assert that subsequent growth cannot update the cache. Removing the guard should fail that test; the current navigation test does not distinguish the guarded and unguarded implementations.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests —
|
| Platform | Categories |
|---|---|
| Android | CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7 |
| iOS | CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7 |
| MacCatalyst | CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7 |
| Windows | CarouselView, CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7 |
🧪 Device tests — Controls.CarouselView, Controls.CollectionView on Windows
❌ Could not queue maui-pr-devicetests: Azure Pipelines did not start maui-pr-devicetests for the dispatch branch run-devicetests/pr40607-46378887659 within 10 minutes. Comment /review run-tests again, or use /azp run maui-pr-devicetests for the full suite.
GPT-6.2 Sol: Run Windows Controls CollectionView and CarouselView device tests for the Items2 cleanup change.
MAI Code 2: Windows Items2 handler cleanup; runs the CollectionView and CarouselView controls device suites on Windows.
🧪 Running — 2 categories on Windows
| Platform | Categories |
|---|---|
| Windows | Controls.CarouselView, Controls.CollectionView |
⏭️ Skipped — what neither suite runs
UI tests — 69 categories, 0 platforms
Categories not run: Accessibility, ActionSheet, ActivityIndicator, Animation, AppLinks, Border, BoxView, Brush, Button, Cells, CheckBox, ContextActions, CustomRenderers, DatePicker, Dispatcher, DisplayAlert, DisplayPrompt, DragAndDrop, Entry, Editor, Effects, Essentials, FlyoutPage, Focus, Fonts, Frame, Gestures, GraphicsView, Image, ImageButton, IndicatorView, InputTransparent, IsEnabled, IsVisible, Label, Layout, Lifecycle, ManualReview, Maps, Navigation, Page, Performance, Picker, ProgressBar, RadioButton, RefreshView, SafeAreaEdges, Shadow, ScrollView, SearchBar, Shape, Slider, SoftInput, Stepper, Switch, SwipeView, Shell1, Shell2, TabbedPage, TableView, TimePicker, TitleView, ToolbarItem, Triggers, ViewBaseTests, VisualStateManager, Window, WebView, Material3
Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.
Device tests — 103 categories, 3 platforms
Platforms not run: Android, iOS, MacCatalyst
Categories not run: Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CheckBox, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay, Graphics, Essentials, BlazorWebView
Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.
🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)
UI tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView |
— |
| iOS | CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView |
— |
| MacCatalyst | CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView |
— |
| Windows | CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7, CarouselView |
CollectionView1, CollectionView2, CollectionView3, CollectionView4, CollectionView5, CollectionView6, CollectionView7 |
GPT-6.2 Sol — Run CollectionView and CarouselView UI coverage for the Windows Items2 fix and the new cross-platform grouped CollectionView regression.
- The Windows Items2 handler and item factory change wrapper cleanup; select the Items2 categories.
- Shared Issue40414 and its four screenshot baselines require all four UI platforms.
- The Shell flyout is only the test setup; no Shell or full-suite run is needed.
MAI Code 2 — Windows-only CollectionView2 cleanup fix; runs CollectionView UI coverage on Windows.
ItemsViewHandler2.Windows.csandWindows/ItemFactory.cschange only the Windows CollectionView2 item cleanup path.- The new shared Issue40414 test is categorized as
CollectionViewand directly covers grouped-item display after Shell navigation. - No other platforms are affected by the production changes; added cross-platform snapshots do not require widening the runtime selection.
Shellis intentionally omitted because the fix is in CollectionView item recreation rather than Shell navigation.
Device tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | — | — |
| iOS | — | — |
| MacCatalyst | — | — |
| Windows | Controls.CollectionView, Controls.CarouselView |
Controls.CollectionView, Controls.CarouselView |
GPT-6.2 Sol — Run Windows Controls CollectionView and CarouselView device tests for the Items2 cleanup change.
- ItemsViewHandler2.Windows.cs and Windows/ItemFactory.cs change item wrapper recycling and observer cleanup; select the two Controls Items2 units.
- The regression page, test, and snapshots are UI-only; no other device platforms or projects are affected.
MAI Code 2 — Windows Items2 handler cleanup; runs the CollectionView and CarouselView controls device suites on Windows.
- Windows-specific changes are in the shared Items2 handler code used by CollectionView2, mapping to
Controls.CollectionView. - Items/Items2 changes also cover CarouselView2 item handling, so
Controls.CarouselViewis included. - Android, iOS, and MacCatalyst are omitted because no production code for those platforms changed.
- No base layout, app startup, shared device infrastructure, or broad mapper code changed, so a full device run is unnecessary.
Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.
…apshot baselines (#41221) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `2e7b2104c43b5a8b8838496ea97c1010a4c90a9e` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8.5/10 | ↑ Test-only change that adds two baseline PNGs and touches no product code.<br>↑ Windows image is byte-identical (MD5) to the CI actual from the windows-cv1 CollectionView1 job artifact.<br>↑ iOS 18.5 and latest lanes produced pixel-identical actuals, and the layout matches the existing ios-26 baseline.<br>↓ maui-pr-uitests has not yet run on this head. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change #40607 added `Issue40414.GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage` to `candidate/11.0.1xx-sr3`. It shipped baselines for `android`, `mac`, `windows` and `ios-26` only. As a result, the **windows-cv1** and **iOS 18.5 (`ios`)** lanes of maui-pr-uitests fail with a missing baseline. This PR adds those two baselines from the CI actuals: - `TestCases.WinUI.Tests/snapshots/windows-cv1/GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage.png`: all three groups (A–G) render correctly. - `TestCases.iOS.Tests/snapshots/ios/GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage.png`: same layout as the committed `ios-26` baseline. The 18.5 and latest lanes are pixel-identical. The separate Windows CollectionViewHandler2 (`windows`) failure of this test is a product issue and is not addressed here. ### Issues Fixed Fixes missing-baseline failures on candidate/11.0.1xx-sr3 maui-pr-uitests (Controls CollectionView1, windows-cv1 and iOS). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…emsSource resets while unloaded (#41278) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `817bc26d9bbbf142fc7b75e41bf579ae265e77b1` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 6/10 | ↑ Loaded-view path is byte-identical to #40962, so its crash/hang protection and device tests (all assert loaded wrappers) are unchanged.<br>↓ No Windows host was available, so the fix is not yet validated locally; maui-pr-uitests Windows CV2 and maui-pr-devicetests on this PR are the evidence that will confirm or refute it. | | Diagnosis confidence | 8/10 | ↑ #40607 PR build 1702675 Windows actual image matches the committed baseline exactly (0 px diff); current sr3 (with #40962) renders the list blank in every test-running build.<br>↑ #40962 sets VirtualView=null, which removes the recreate-on-measure path #40607 depended on.<br>↓ That the page is unloaded during OnAppearing is inferred from Shell/WinUI ordering, not traced. | | Evidence fit | 8/10 | ↑ Failure begins with the first test-running sr3 builds after #40962 merged; the test only exists on sr3. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change `Issue40414.GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage` fails on Windows CV2 in every sr3 maui-pr-uitests build because the grouped list is blank. **Root cause.** Two fixes that merged straight into `candidate/11.0.1xx-sr3` conflict: - #40607 (fixes #40414) detached the item content but kept `wrapper.VirtualView`. When WinUI re-measures a wrapper, `EnsurePlatformViewCreated` rebuilds the view. - #40962 (fixes #40655) replaced that with `ReleaseContent()`, which also sets `VirtualView = null`. This was deliberate, so that retired wrappers cannot recreate content during measurement while the list is visible. The repro page is a cached Shell page that resets `ItemsSource` in `OnAppearing`, while the page is still unloaded. When the page loads again, WinUI reuses those realized wrappers. Their `VirtualView` is now null, so nothing renders. **Evidence.** - The #40607 PR build [1702675](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1702675) produced a Windows image identical to the committed baseline (0 px diff). - sr3 [1708237](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1708237) shows only the "Flyout2Content" title. **Fix.** `CleanUpCollectionViewSource` now chooses the release mode based on whether the wrapper is loaded: - **Loaded wrappers:** call `ReleaseContent()` (unchanged #40962 behaviour). - **Unloaded wrappers:** call a new `DetachContent()`. It unwires the size observer and sets `Content = null`, keeping `VirtualView`. Handlers are still disconnected after the native content is detached, so #40962's ordering is preserved. The wrapper can then recreate its view when the page loads again. **Validation.** - Not run locally: no Windows host is available. - This PR relies on maui-pr-uitests (Windows CV2 `Issue40414`) and maui-pr-devicetests (`CollectionView2MemoryTests.Windows`, whose tests all use loaded wrappers). ### Issues Fixed Fixes #40414 regression on candidate/11.0.1xx-sr3 (re-broken by #40962) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Issue Details:
On Windows, a grouped CollectionView using CV2 can appear empty after resetting ItemsSource or navigating back to the page.
Root Cause:
The item handler is disconnected during cleanup, but its wrapper retains the old, empty native view.
Description of Changes:
After disconnecting the handler, remove the old size observer, clear the wrapper’s content and unwire the Unloaded event. This allows the native view to be recreated when needed.
Issues Fixed
Fixes #40414
Tested the behavior in the following platforms.
Before-40414.mp4
After-40414.mp4