diff --git a/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs b/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs
index 2c649015b880..a6ef8ef550c8 100644
--- a/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs
+++ b/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs
@@ -1,12 +1,14 @@
#nullable disable
using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
namespace Microsoft.Maui.Controls.Internals
{
///
public static class PropertyPropagationExtensions
{
- internal static void PropagatePropertyChanged(string propertyName, Element element, IEnumerable children)
+ internal static void PropagatePropertyChanged(string propertyName, Element element, IReadOnlyList children)
{
if (propertyName == null || propertyName == VisualElement.FlowDirectionProperty.PropertyName)
SetFlowDirectionFromParent(element);
@@ -26,10 +28,12 @@ internal static void PropagatePropertyChanged(string propertyName, Element eleme
if (propertyName == null || propertyName == Shell.NavBarIsVisibleProperty.PropertyName)
BaseShellItem.PropagateFromParent(Shell.NavBarIsVisibleProperty, element);
- foreach (var child in children)
+ foreach (var child in children.ToArray())
{
if (child is IPropertyPropagationController view)
+ {
view.PropagatePropertyChanged(propertyName);
+ }
}
}
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml
new file mode 100644
index 000000000000..d78709e06c5a
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml.cs
new file mode 100644
index 000000000000..158972989b0a
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml.cs
@@ -0,0 +1,19 @@
+using System.Collections.ObjectModel;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [Issue(IssueTracker.Github, 28162, "Crash occurs when switching CollectionView.IsVisible right after setting ItemsSource", PlatformAffected.iOS)]
+ public partial class Issue28162 : ContentPage
+ {
+ public Issue28162()
+ {
+ InitializeComponent();
+ }
+
+ private void Button_Clicked(object sender, EventArgs e)
+ {
+ CollectionView.ItemsSource = new ObservableCollection { "Item 1", "Item 2", "Item 3" };
+ CollectionView.IsVisible = !CollectionView.IsVisible;
+ }
+ }
+}
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28162.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28162.cs
new file mode 100644
index 000000000000..20b6c75f089a
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28162.cs
@@ -0,0 +1,23 @@
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue28162 : _IssuesUITest
+ {
+ public Issue28162(TestDevice testDevice) : base(testDevice)
+ {
+ }
+
+ public override string Issue => "Crash occurs when switching CollectionView.IsVisible right after setting ItemsSource";
+
+ [Test]
+ [Category(UITestCategories.CollectionView)]
+ public void SwitchingVisibilityAndChangingItemsSourceShouldNotCrash()
+ {
+ App.WaitForElement("button");
+ App.Click("button");
+ }
+ }
+}
\ No newline at end of file