-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed CollectionView does not update layout correctly when ItemsSource changes #30978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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();
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
--- 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
…e changes (dotnet#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
…e changes (#30978) * Fixed CollectionView does not update layout correctly when ItemsSource changes * Optimized fix
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