Skip to content

Commit

Permalink
Toggling Header/Footer in CollectionView Dynamically throws an except…
Browse files Browse the repository at this point in the history
…ion (#25743)

* Fixed - 25724 : "ObjectDisposedException" When Toggling Header/Footer in CollectionView Dynamically

* updating nullable enable property

* reverting unnecessary changes

---------

Co-authored-by: praveenkumarkarunanithi <praveenkumar.karunanithi@syncfusion.com>
  • Loading branch information
Vignesh-SF3580 and praveenkumarkarunanithi authored Nov 18, 2024
1 parent 7143174 commit 3c9c96b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ internal void UpdateView(object view, DataTemplate viewTemplate, ref UIView uiVi

uiView?.Dispose();
uiView = null;

formsElement?.Handler?.DisconnectHandler();
formsElement = null;
}
else
Expand Down
51 changes: 51 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25724.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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.Issue25724"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Name="ThisMainPage"
Title="Main Page">

<Grid RowDefinitions="Auto,*">

<HorizontalStackLayout
Grid.Row="0"
Padding="20"
HorizontalOptions="Center"
Spacing="20">
<Button AutomationId="ToggleHeaderButton" Text="Toggle Header" Clicked="ToggleHeader"></Button>
<Button AutomationId="ToggleFooterButton" Text="Toggle Footer" Clicked="ToggleFooter"></Button>
</HorizontalStackLayout>

<CollectionView x:Name="CollectionView" Grid.Row="1" ItemsSource="{Binding ItemList}">

<CollectionView.Header>
<Label
Padding="10"
FontAttributes="Bold"
FontSize="Large"
Text="This Is A Header" />
</CollectionView.Header>

<CollectionView.ItemTemplate>
<DataTemplate>
<Label Padding="20,5,5,5" Text="{Binding .}" />
</DataTemplate>
</CollectionView.ItemTemplate>

<CollectionView.EmptyView>
<Label Padding="20,5,5,5" Text="Empty" />
</CollectionView.EmptyView>

<CollectionView.Footer>
<Label
Padding="10"
FontAttributes="Bold"
FontSize="Large"
Text="This Is A Footer" />
</CollectionView.Footer>

</CollectionView>

</Grid>
</ContentPage>
54 changes: 54 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25724.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#nullable enable
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 25724, "ObjectDisposedException When Toggling Header/Footer in CollectionView Dynamically", PlatformAffected.iOS)]

public partial class Issue25724 : ContentPage
{
object? header;
object? footer;
public Issue25724()
{
InitializeComponent();
BindingContext = new Issue25724ViewModel();
}

void ToggleHeader(object sender, System.EventArgs e)
{
header = CollectionView.Header ?? header;

if (CollectionView.Header == null)
CollectionView.Header = header;
else
CollectionView.Header = null;
}

void ToggleFooter(object sender, System.EventArgs e)
{
footer = CollectionView.Footer ?? footer;

if (CollectionView.Footer == null)
CollectionView.Footer = footer;
else
CollectionView.Footer = null;
}

internal class Issue25724ViewModel
{
public ObservableCollection<string> ItemList { get; set; }
public Issue25724ViewModel()
{
// Initialize the ItemList
ItemList = new ObservableCollection<string>();
}

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if IOS || MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue25724 : _IssuesUITest
{
public Issue25724(TestDevice device) : base(device) { }

public override string Issue => "ObjectDisposedException When Toggling Header/Footer in CollectionView Dynamically";

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewDynamicHeaderShouldNotCrashOnDisplay()
{
App.WaitForElement("This Is A Header");
App.Tap("ToggleHeaderButton"); // This is the button that toggles the header to null
App.Tap("ToggleHeaderButton");// This is the button that toggles the header back to the original value
App.WaitForElement("This Is A Header");
}
}
}
#endif

0 comments on commit 3c9c96b

Please sign in to comment.