[WinUI][CV2] CollectionView2 Handler Implementation for Windows#34600
Draft
SuthiYuvaraj wants to merge 84 commits intonet11.0from
Draft
[WinUI][CV2] CollectionView2 Handler Implementation for Windows#34600SuthiYuvaraj wants to merge 84 commits intonet11.0from
SuthiYuvaraj wants to merge 84 commits intonet11.0from
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34600Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34600" |
9 tasks
Contributor
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This was referenced Mar 24, 2026
Open
Open
Collaborator
|
|
Contributor
|
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? |
Contributor
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
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 legacyListView-based CollectionView implementation with a modern, performant, and feature-complete handler across all platforms.The CV2 handler on Windows leverages WinUI's
ItemsRepeatercontrol 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 allCollectionViewproperties and commands to the WinUIItemsRepeater-based view. Handles layout mapping (LinearItemsLayout→StackLayout,GridItemsLayout→UniformGridLayout), scroll management, selection, snapping, incremental loading, andRefreshViewintegration.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 WinUIUserControlhosting theItemsRepeaterinside aScrollViewer, with support for Header/Footer, EmptyView overlay, andRefreshContainerwrapping.GroupableUniformGridLayout.cs— Custom layout that extendsUniformGridLayoutbehavior to support grouped collection scenarios with proper group header/footer sizing.Item Source & Templating Pipeline
ItemFactory.cs—IElementFactoryimplementation that creates WinUI elements from MAUIDataTemplate/DataTemplateSelector, manages recycling, and handles grouped vs flat item sources.ObservableItemTemplateCollection2.cs— BridgesINotifyCollectionChangedsource collections toItemsRepeater-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 byItemsRepeater, 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 theCollectionView2runtime feature flag.RuntimeFeature.cs— Added theCollectionView2feature switch for conditional handler activation.PublicAPI.Unshipped.txt— Added 43 new public API entries for the Windows CV2 surface area.Build property integration — Updated
.csprojfiles and build targets to include theUseCollectionView2MSBuild property for opt-in activation.Issues Fixed
The following issues are addressed by this implementation and the associated bug fixes:
IEnumerablesource rendering not working in CollectionViewMajor Functional Improvements
GridItemsLayoutspan width; fixedLayoutOptionsalignment; fixedCornerRadiusrendering; fixed item margin and pointer-over visuals.PullToRefreshwithScrollViewer; fixedKeepScrollOffset/KeepItemsInView; fixedScrollToon unloaded view; fixed horizontal flicker.ScrollTofor grouped items.DataTemplatechange.DataTemplateSelectornot updating onCollectionChanged.Platforms Affected
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
GroupHeader Placement
GroupHeader is now rendered without additional spacing, ensuring proper alignment with items and eliminating the extra gaps observed in CV1.
Output Screenshot
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
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