Skip to content

[WinUI][CV2] CollectionView2 Handler Implementation for Windows#34600

Draft
SuthiYuvaraj wants to merge 84 commits intonet11.0from
BugFixes_WinUI_CV2
Draft

[WinUI][CV2] CollectionView2 Handler Implementation for Windows#34600
SuthiYuvaraj wants to merge 84 commits intonet11.0from
BugFixes_WinUI_CV2

Conversation

@SuthiYuvaraj
Copy link
Copy Markdown
Contributor

@SuthiYuvaraj SuthiYuvaraj commented Mar 23, 2026

Introduction

This PR implements the CollectionView2 (CV2) handler for Windows (WinUI), bringing the new ItemsRepeater-based CollectionView architecture to the Windows platform. This is part of the ongoing effort to replace the legacy ListView-based CollectionView implementation with a modern, performant, and feature-complete handler across all platforms.

The CV2 handler on Windows leverages WinUI's ItemsRepeater control as the virtualizing layout engine, providing better performance, smoother scrolling, and more consistent behavior aligned with the CV2 implementations on Android, iOS, and MacCatalyst.

Description of Changes

New Windows CV2 Handler Architecture

  • ItemsViewHandler2.Windows.cs — Core handler implementation mapping all CollectionViewproperties and commands to the WinUI ItemsRepeater-based view. Handles layout mapping (LinearItemsLayoutStackLayout, GridItemsLayoutUniformGridLayout), scroll management, selection, snapping, incremental loading, and RefreshView integration.

  • CollectionViewHandler2.Windows.cs — CollectionView-specific handler derived from the base items view handler, implementing selection modes (None, Single, Multiple), visual states, pre-selection, and pointer-based item interaction.

  • MauiItemsView.cs — Custom WinUI UserControl hosting the ItemsRepeater inside a ScrollViewer, with support for Header/Footer, EmptyView overlay, and RefreshContainer wrapping.

  • GroupableUniformGridLayout.cs — Custom layout that extends UniformGridLayout behavior to support grouped collection scenarios with proper group header/footer sizing.

Item Source & Templating Pipeline

  • ItemFactory.csIElementFactory implementation that creates WinUI elements from MAUI DataTemplate/DataTemplateSelector, manages recycling, and handles grouped vs flat item sources.

  • ObservableItemTemplateCollection2.cs — Bridges INotifyCollectionChanged source collections to ItemsRepeater-compatible observable collections, translating insert/remove/replace/move/reset operations.

  • GroupedItemTemplateCollection2.cs — Flattens grouped source data (with group headers, items, and group footers) into a single linear collection consumable by ItemsRepeater, tracking group boundary indices.

  • TemplatedItemSourceFactory2.cs — Factory that selects the appropriate templated collection type (observable, grouped, or enumerable context) based on the items source characteristics.

  • ItemTemplateContext2.cs, ItemTemplateContextEnumerable2.cs, ItemTemplateContextList2.cs — Context wrappers for item template binding.

Supporting Changes

  • ItemsViewExtensions.Windows.cs — New extension class with helper methods for converting MAUI layout types, snap point settings, and sizing strategies to their WinUI equivalents.

  • ItemsViewStyles.xaml — Updated WinUI resource dictionary with refined styles and templates for CV2 items, group headers/footers, header/footer, and empty view containers.

  • AppHostBuilderExtensions.cs — Registered the CV2 handler mappings for Windows in the MAUI host builder, gated behind the CollectionView2 runtime feature flag.

  • RuntimeFeature.cs — Added the CollectionView2 feature switch for conditional handler activation.

  • PublicAPI.Unshipped.txt — Added 43 new public API entries for the Windows CV2 surface area.

  • Build property integration — Updated .csproj files and build targets to include the UseCollectionView2 MSBuild property for opt-in activation.

Issues Fixed

The following issues are addressed by this implementation and the associated bug fixes:

Issue Description
#28895 CollectionView2 Implementation
#22320 IEnumerable source rendering not working in CollectionView
#26187 UITest failure — CollectionView items not displaying correctly
#27797 UITest failure — CollectionView interaction issues
#28212 CollectionView item layout/rendering bug
#31899 CollectionView Windows-specific rendering issue
#32543 CollectionView selection/interaction bug
#33487 CollectionView layout calculation issue

Major Functional Improvements

  • Layout: Fixed GridItemsLayout span width; fixed LayoutOptions alignment; fixed CornerRadius rendering; fixed item margin and pointer-over visuals.
  • Scrolling: Fixed PullToRefresh with ScrollViewer; fixed KeepScrollOffset/KeepItemsInView; fixed ScrollTo on unloaded view; fixed horizontal flicker.
  • Grouping: Fixed group header/footer rendering; fixed grouped grid layout; fixed ScrollTo for grouped items.
  • EmptyView: Fixed visibility toggling; removed unnecessary measure pass.
  • MeasureFirstItem: Fixed incorrect size with URL-based images; fixed size recalculation on DataTemplate change.
  • Data: Fixed DataTemplateSelector not updating on CollectionChanged.
  • Orientation: Fixed orientation switch not updating layout.

Platforms Affected

  • Windows (WinUI)

UI Difference from CV1

Selection UI
Selection appearance differs from CV1, where the selected item is now highlighted using a border that fully wraps the item, instead of the previous visual style.

Output Screenshot

CV1 Behavior CV2 Behavior
Before Fix After Fix
Before Fix - Multi Select After Fix - Multi Select

GroupHeader Placement
GroupHeader is now rendered without additional spacing, ensuring proper alignment with items and eliminating the extra gaps observed in CV1.

Output Screenshot

CV1 Behavior CV2 Behavior
Before Fix After Fix

EmptyView Behavior
EmptyView is positioned between the header and footer, and its sizing differs from CV1 as it does not occupy the full available width, resulting in a more constrained layout.

Output Screenshot

CV1 Behavior CV2 Behavior
Before Fix After Fix

Known Limitations

Drag and Drop Support
Drag and drop functionality available in CV1 is not included in this implementation and will be addressed separately.

Testing

  • Existing CollectionView UITests passing on Windows with CV2 handler enabled
  • Manual testing scenarios validated for: flat lists, grouped lists, grid layouts, selection modes, scrolling, snap points, pull-to-refresh, empty views, header/footer, incremental loading, and data template selectors

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34600

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34600"

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 23, 2026
@sheiksyedm sheiksyedm added platform/windows area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution labels Mar 23, 2026
@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Mar 28, 2026

⚠️ Merge Conflict Detected — This PR has merge conflicts with its target branch. Please rebase onto the target branch and resolve the conflicts.

@daltzctr
Copy link
Copy Markdown
Contributor

daltzctr commented Mar 31, 2026

Any benchmarks on render performance for N items? What about scrolling performance across complex children? Does the issue where ghosting would occur if you scrolled fast through a CV filled with complex children?

@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants