Skip to content

Fix for CollectionView with GridItemsLayout (Span=1) doesn't adapt to window width reduction on Windows platform#31038

Merged
PureWeen merged 7 commits intodotnet:inflight/currentfrom
praveenkumarkarunanithi:fix-23702
Oct 31, 2025
Merged

Fix for CollectionView with GridItemsLayout (Span=1) doesn't adapt to window width reduction on Windows platform#31038
PureWeen merged 7 commits intodotnet:inflight/currentfrom
praveenkumarkarunanithi:fix-23702

Conversation

@praveenkumarkarunanithi
Copy link
Contributor

@praveenkumarkarunanithi praveenkumarkarunanithi commented Aug 6, 2025

Root Cause

In the single-column case (Span = 1), setting the ItemWidth on the native UWP ItemsWrapGrid to match the full container width causes the layout system to treat the item size as fixed. As a result, no size change is detected during window resizing, and the SizeChanged event does not fire. In contrast, when Span > 1, the ItemWidth is smaller than the container, allowing the layout to reflow and correctly trigger SizeChanged.
This behavior aligns with UWP documentation, which states that SizeChanged occurs only when ActualWidth or ActualHeight changes, and does not fire “if the position of the object within a parent container changes, but not the size.”

Description of Change

The fix updates the UpdateItemSize method in FormsGridView.cs to conditionally skip setting the ItemWidth when the layout has only one column (Span == 1). In this case, ItemWidth remains at its default value, allowing the native UWP ItemsWrapGrid to use its built-in Auto layout behavior. This ensures that the control remains responsive and correctly handles window size changes.

Issues Fixed

Fixes #23702
#26083

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshots

Before Issue Fix After Issue Fix
withoutfix withfix

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 6, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@praveenkumarkarunanithi! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@praveenkumarkarunanithi praveenkumarkarunanithi changed the title Fix 23702 Fix for CollectionView with GridItemsLayout (Span=1) doesn't adapt to window width reduction on Windows platform Aug 6, 2025
@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 6, 2025
@praveenkumarkarunanithi praveenkumarkarunanithi marked this pull request as ready for review August 8, 2025 11:05
Copilot AI review requested due to automatic review settings August 8, 2025 11:05
@praveenkumarkarunanithi praveenkumarkarunanithi requested a review from a team as a code owner August 8, 2025 11:05
Copy link
Contributor

Copilot AI left a 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 window resizing issue with CollectionView using GridItemsLayout on Windows where single-column layouts (Span=1) don't properly adapt when the window width is reduced. The root cause is that setting ItemWidth to the full container width prevents the UWP SizeChanged event from firing during resize operations.

  • Conditionally skips setting ItemWidth for single-column layouts (Span=1) to allow native Auto layout behavior
  • Adds comprehensive UI test coverage to validate the fix behavior
  • Maintains existing functionality for multi-column layouts (Span>1)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/Core/Platform/Windows/CollectionView/FormsGridView.cs Core fix that conditionally clears ItemWidth for single-column GridItemsLayout
src/Controls/tests/TestCases.HostApp/Issues/Issue23702.cs UI test page demonstrating the CollectionView resize behavior
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23702.cs Automated test validating that items resize correctly when width decreases
Comments suppressed due to low confidence (1)

Comment on lines +68 to +74
label.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "Width" && sender is Label sl && sl.Width > 0)
{
_widthLabel.Text = Math.Round(sl.Width).ToString();
}
};
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PropertyChanged event handler is attached inside the DataTemplate factory method, which means a new handler is created for every item in the collection. This could lead to memory leaks if items are recycled. Consider using a WeakEventManager or detaching the handler when appropriate.

Suggested change
label.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == "Width" && sender is Label sl && sl.Width > 0)
{
_widthLabel.Text = Math.Round(sl.Width).ToString();
}
};
WeakEventManager<PropertyChangedEventArgs>.AddHandler(label, nameof(label.PropertyChanged), (sender, e) =>
{
if (e.PropertyName == "Width" && sender is Label sl && sl.Width > 0)
{
_widthLabel.Text = Math.Round(sl.Width).ToString();
}
});

Copilot uses AI. Check for mistakes.
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


[Test]
[Category(UITestCategories.CollectionView)]
public void ItemsWrapGridShouldUpdateBasedOnCollectionViewSize()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshot on Mac and Windows:
ItemsWrapGridShouldUpdateBasedOnCollectionViewSize

image

Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz updated the images for UI test from CI.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alex3696
Copy link

Are there any chances that this error will be fixed in maui 9? I've been waiting for a long time...

@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Oct 24, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current October 31, 2025 20:30
@PureWeen PureWeen merged commit fdb9206 into dotnet:inflight/current Oct 31, 2025
78 of 79 checks passed
@PureWeen PureWeen added this to the .NET 10.0 SR1 milestone Nov 7, 2025
PureWeen pushed a commit that referenced this pull request Nov 11, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 11, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 14, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
… window width reduction on Windows platform (#31038)

* fix update.

* updated test case

* optimised test case

* Update FormsGridView.cs

* updated test case for 26083

* updated UI test images from CI

* updated UI test from CI-2
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2025
@PureWeen PureWeen moved this from Todo to Done in MAUI SDK Ongoing Dec 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[MAUI]I1_Layout-Vertical list and Grid content cannot adapt when the window is reduced

5 participants