Fixed CollectionView does not update layout correctly when ItemsSource changes#30978
Merged
PureWeen merged 2 commits intodotnet:inflight/currentfrom Aug 4, 2025
Merged
Fixed CollectionView does not update layout correctly when ItemsSource changes#30978PureWeen merged 2 commits intodotnet:inflight/currentfrom
PureWeen merged 2 commits intodotnet:inflight/currentfrom
Conversation
Contributor
|
Hey there @@Dhivya-SF4094! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a layout issue where CollectionView fails to display items when ItemsSource is set at runtime after being initially null. The problem occurs because the layout system measures the CollectionView with zero height when no items are present, and continues to receive zero height measurements even after items are added.
Key changes:
- Added fallback logic in
GetDesiredSize()method to use base implementation when controller returns zero dimensions - Added comprehensive UI test to validate the fix across platforms
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs |
Added fallback to base.GetDesiredSize() when Controller.GetSize() returns zero width/height |
src/Controls/tests/TestCases.HostApp/Issues/Issue30953.cs |
Created test page demonstrating CollectionView with runtime ItemsSource assignment |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30953.cs |
Added automated UI test to verify CollectionView displays items after runtime ItemsSource change |
Comments suppressed due to low confidence (2)
src/Controls/tests/TestCases.HostApp/Issues/Issue30953.cs:8
- The field name 'Countries' should follow C# naming conventions and be lowercase 'countries' since it's a private field.
private ObservableCollection<string> Countries = new();
src/Controls/tests/TestCases.HostApp/Issues/Issue30953.cs:13
- The CollectionView2 instance lacks an AutomationId. According to the coding guidelines, AutomationIds should be unique and present on all testable UI elements to ensure WaitForElement can locate the correct element in automated tests.
var collectionView = new CollectionView2();
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
rmarinho
approved these changes
Aug 4, 2025
PureWeen
pushed a commit
that referenced
this pull request
Aug 4, 2025
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
github-actions bot
pushed a commit
that referenced
this pull request
Aug 7, 2025
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
PureWeen
added a commit
that referenced
this pull request
Aug 8, 2025
--- title: ".NET MAUI main-to-inflight-candidate Release Notes" date: 2025-08-08 version: "main-to-inflight-candidate" comparison: "main...inflight/candidate" full_changelog: "main...inflight/candidate" description: "Release notes for .NET MAUI main-to-inflight-candidate, covering 10 commits with enhancements and improvements." --- # .NET MAUI main-to-inflight-candidate Release Notes **Version:** main-to-inflight-candidate **Comparison:** main...inflight/candidate **Generated:** August 08, 2025 **Last Updated:** August 08, 2025 **Latest Commit Range:** 7f99494 **Total Commits:** 10 ## What's Changed This release includes 10 commits with various improvements, bug fixes, and enhancements to the .NET MAUI framework. ### .NET MAUI Product Fixes - Update MauiRecyclerView.cs by @github-actions[bot] in #31050 - Added the GraphicsView base images for Windows and mac platforms by @nivetha-nagalingam in #31018 - Fixed CollectionView does not update layout correctly when ItemsSource changes by @Dhivya-SF4094 in #30978 - Fixes #30953 - Fix duplicate app icon resizing by @jeremy-visionaid in #30920 - Fixed GraphicsView event handlers are triggered even when IsEnabled is set to False by @Dhivya-SF4094 in #30755 - Fixes #30649 - [iOS, Mac] Fix for Picker title is not displayed again when SelectedIndex is set to -1 by @HarishwaranVijayakumar in #30486 - Fixes #31011, #30463 ### Testing - [Testing] Feature matrix UITest Cases for GraphicsView Control by @nivetha-nagalingam in #30781 - [Testing] Feature matrix UITest Cases for HybridWebView Control by @NafeelaNazhir in #30613 ### Housekeeping - [create-pull-request] automated change by @github-actions[bot] in #30890 - [create-pull-request] automated change by @github-actions[bot] in #30700 **Full Changelog**: main...inflight/candidate
SuthiYuvaraj
pushed a commit
to SuthiYuvaraj/maui
that referenced
this pull request
Aug 12, 2025
…e changes (dotnet#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
rmarinho
pushed a commit
that referenced
this pull request
Aug 13, 2025
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
This was referenced Aug 15, 2025
This was referenced Aug 18, 2025
Closed
Bump Microsoft.AspNetCore.Components.WebView.Maui from 9.0.90 to 9.0.100
ILoveDotNet/ilovedotnet#467
Merged
4 tasks
5 tasks
10 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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
The CollectionView is initially loaded with its ItemsSource set to null. When the ItemsSource is updated at runtime, the items are not displayed, and the CollectionView height remains at 0, resulting in no visible content.
Root Cause
Description of Change
Added a fallback in GetDesiredSize to return base.GetDesiredSize() when Controller.GetSize() returns a zero width or height. This ensures proper layout measurement and allows the CollectionView to render correctly once data is set.
Reference
if (potentialContentSize == null)
{
return size;
}
maui/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs
Lines 160 to 163 in 3ca9527
Validated the behaviour in the following platforms
Issues Fixed:
Fixes #30953
Screenshots
30953_BeforeFix.mov
30953_AfterFix.mov