-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggling Header/Footer in CollectionView Dynamically throws an exception #25743
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
rmarinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this fix on ItemsViewController2 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmarinho ,
I've tested this scenario with CollectionViewHandler2, and since the header and footer handling differs in that implementation, the issue does not occur. Dynamically setting the header, footer, and empty view to null works without any exceptions in CollectionViewHandler2, so this fix isn't needed there.