Skip to content

Regression Issue: CollectionView SizeChanged does not work in SR6 but it works in SR5 (.NET 8) #23029

@malsabi

Description

@malsabi

Description

I have a CollectionView and a registered behavior called 'ResponsiveGridBehavior'. The behavior hooks the 'SizeChanged' event to control the number of span columns. The behavior is intended to work only on Desktop Idiom like Windows, Mac Catalyst

public class ResponsiveGridBehavior : Behavior<CollectionView>
{
	protected override void OnAttachedTo(CollectionView bindable)
	{
		base.OnAttachedTo(bindable);
		if (DeviceInfo.Idiom == DeviceIdiom.Desktop)
			bindable.SizeChanged += OnSizeChanged;
	}

	protected override void OnDetachingFrom(CollectionView bindable)
	{
		if (DeviceInfo.Idiom == DeviceIdiom.Desktop)
			bindable.SizeChanged -= OnSizeChanged;
		base.OnDetachingFrom(bindable);
	}

	private void OnSizeChanged(object? sender, EventArgs e)
	{
		if (sender is CollectionView collectionView && collectionView.ItemsLayout is GridItemsLayout gridItemsLayout)
		{
			double maxWidthPerItem = Application.Current!.GetResource<double>("CardMaximumWidth", 300);
			gridItemsLayout.Span = Math.Max(1, (int)(collectionView.Width / maxWidthPerItem));
		}
	}
}

After updating to SR6 the event 'SizeChanged' is never called.

Steps to Reproduce

No response

Link to public reproduction project repository

https://github.com/malsabi/CollectionViewSizeChangedIssue

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

Windows, macOS

Affected platform versions

No response

Did you find any workaround?

I had to roll back to SR5.

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

area-controls-collectionviewCollectionView, CarouselView, IndicatorViewfixed-in-8.0.61fixed-in-9.0.0-preview.6.24327.7i/regressionThis issue described a confirmed regression on a currently supported versionp/1Work that is important, and has been scheduled for release in this or an upcoming sprintplatform/macosmacOS / Mac Catalystplatform/windowss/needs-attentionIssue has more information and needs another looks/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions