-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggling Header/Footer in CollectionView Dynamically throws an except…
…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
1 parent
7143174
commit 3c9c96b
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Controls/tests/TestCases.HostApp/Issues/Issue25724.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
src/Controls/tests/TestCases.HostApp/Issues/Issue25724.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25724.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |