Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#nullable disable
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Maui.Controls.Internals
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Internals/PropertyPropagationExtensions.xml" path="Type[@FullName='Microsoft.Maui.Controls.Internals.PropertyPropagationExtensions']/Docs/*" />
public static class PropertyPropagationExtensions
{
internal static void PropagatePropertyChanged(string propertyName, Element element, IEnumerable children)
internal static void PropagatePropertyChanged(string propertyName, Element element, IReadOnlyList<IVisualTreeElement> children)
{
if (propertyName == null || propertyName == VisualElement.FlowDirectionProperty.PropertyName)
SetFlowDirectionFromParent(element);
Expand All @@ -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);
}
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue28162">
<VerticalStackLayout>
<Button Text="Toggle visibility"
AutomationId="button"
Clicked="Button_Clicked"/>
<CollectionView IsVisible="True"
HorizontalOptions="Center"
VerticalOptions="Center"
x:Name="CollectionView">
<CollectionView.Header>
<ContentView HeightRequest="50"
BackgroundColor="Green"/>
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border StrokeShape="RoundRectangle 10"
Padding="20"
Stroke="Red">
<Label HorizontalOptions="Center"
VerticalOptions="Center"
Text="{Binding .}"/>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.Footer>
<ContentView HeightRequest="50"
BackgroundColor="Green"/>
</CollectionView.Footer>
</CollectionView>
</VerticalStackLayout>
</ContentPage>
19 changes: 19 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28162.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<string> { "Item 1", "Item 2", "Item 3" };
CollectionView.IsVisible = !CollectionView.IsVisible;
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Loading