Skip to content

[WinUI][CV2] Follow-ups from CollectionView2 Windows handler (#34600) #36068

Open

Description

@PureWeen

Tracking issue for non-blocking follow-ups identified during review of #34600 (WinUI CollectionView2 handler, now merged). None of these blocked the merge — each is an edge case or pre-existing parity item suitable for an independent follow-up PR. Surfaced by multi-model adversarial review across rounds 1–4 on #34600.

Null source-item handling

When a data source contains null elements, three CV2 Windows consumers mishandle the now-reachable null (the null-skip guard was intentionally removed in ObservableItemTemplateCollection2 to fix index desync, so null items now flow through):

  • ItemFactory.cs:124 — null item renders in the Selected visual state. With SelectionMode=Single and nothing selected, object.Equals(SelectedItem=null, Item=null) returns true, so a null row paints as selected. Fix: guard templateContext.Item is not null before the equality check.
  • MauiItemsView.DragDrop.cs:1266 — stale drag index on null cells. UpdateAllContainerIndices skips null-item containers, so their Tag goes stale after a reorder and dragging the blank cell can move the wrong row. Fix: clear the Tag when the item is null (or resolve the index via GetElementIndex).
  • GroupedItemTemplateCollection2.cs:324 — grouped Replace with a null value desyncs. HandleGroupItemsReplace still has if (item is null) continue;, leaving the old context in place and emitting a malformed Replace. Fix: mirror the null-parity handling used in the flat collection.

Source / layout semantics

  • ItemsViewHandler2.Windows.cs:362 — non-grouped collection-of-collections is flattened. When IsGrouped=false but ItemsSource items are themselves non-string IEnumerable, the IsItemsSourceGrouped heuristic (L360) flattens the source. CV1 instead binds each inner collection as a single item. Also reachable if a model type happens to implement IEnumerable. Non-crashing behavior difference vs CV1. Fix: gate the else-branch flatten on IsGrouped.

INCC robustness (pre-existing CV1 parity — low priority)

  • ObservableItemTemplateCollection2.cs:420 / :239,247 — indexless Replace/Move can throw. A custom INotifyCollectionChanged source raising Replace/Move with a -1 starting index computes OldStartingIndex + index → this[-1] → ArgumentOutOfRangeException. Not a regression — the current CV1 ObservableItemTemplateCollection (Platform/Windows/CollectionView) is line-for-line identical, and Remove in both already guards < 0 with a Reset(). Rare trigger (ObservableCollection<T> always supplies indices); the grouped sibling already bounds-guards via ResetWithoutResubscribe(). Fix (ideally cross-platform): mirror the Remove < 0 → Reset() guard in Replace/Move.

CI / pipeline

  • eng/pipelines/common/ui-tests-build-sample.yml — duplicate ui-tests-samples-windows_failed artifact name. Two failure-publish steps collide when platform=windows && useWindowsCV1=false && failed(): one condition is (windows, cv1=false, failed) and another is (windows, failed), both publishing ui-tests-samples-windows_failed_$(System.JobAttempt). The second publish errors on the duplicate artifact name. Fix: make the conditions mutually exclusive (or give the CV1/default lanes distinct artifact names).

Needs verification (cleanup code was added since these were flagged — may already be mitigated)

  • ItemFactory.cs:233 — confirm RecycleElement clears BindingContext/DataContext on pooled containers (stale-binding risk).
  • ItemFactory.cs:420 — confirm MeasureFirstItem size cache can't be polluted by a recycled first item.

Already addressed (no action needed)

  • ObservableItemTemplateCollection2.cs _innerCollectionChange is now correctly wrapped in try/finally. ✓

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewcollectionview-winui-cv2platform/windowss/triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions