Fixed - Using CollectionView.EmptyView results in an Exception on Windows#28367
Merged
PureWeen merged 10 commits intodotnet:inflight/currentfrom Mar 18, 2025
Merged
Fixed - Using CollectionView.EmptyView results in an Exception on Windows#28367PureWeen merged 10 commits intodotnet:inflight/currentfrom
PureWeen merged 10 commits intodotnet:inflight/currentfrom
Conversation
Contributor
|
Hey there @KarthikRajaKalaimani! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an exception that occurs on Windows when navigating back to a page containing a CollectionView with an EmptyView. Key changes include:
- Updating ItemsViewHandler.Windows.cs to disconnect the EmptyView’s handler during cleanup.
- Adding new UI test cases in TestCases.Shared.Tests and TestCases.HostApp to cover the issue.
- Ensuring the UI navigation flow correctly triggers and verifies the fix for issue #28212.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28212.cs | New UI test for reproducing the exception scenario. |
| src/Controls/tests/TestCases.HostApp/Issue28212.cs | Updated UI pages for navigation and triggering the issue. |
| src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs | Modified to disconnect the EmptyView's handler to avoid reusing a stale view. |
|
|
||
| public class Issue28212_Page2 : ContentPage | ||
| { | ||
| public ObservableCollection<string> Items { get; } = []; |
There was a problem hiding this comment.
The syntax '[]' is not a valid way to initialize an ObservableCollection in C#. Replace it with 'new ObservableCollection();' to correctly instantiate the collection.
Suggested change
| public ObservableCollection<string> Items { get; } = []; | |
| public ObservableCollection<string> Items { get; } = new ObservableCollection<string>(); |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
approved these changes
Mar 14, 2025
Member
|
Do we also need to call ? ItemsView.RemoveLogicalChild(_formsEmptyView); |
PureWeen
pushed a commit
that referenced
this pull request
Mar 26, 2025
…dows (#28367) * Fixed Using CollectionView.EmptyView results in an Exception on Windows * Test case written and fix slightly modified * Test case modified * Snap added for android and iOS * Test case modified * snap removed * Test case modified * Removed curly braces * Test case modified
PureWeen
pushed a commit
that referenced
this pull request
Mar 26, 2025
…dows (#28367) * Fixed Using CollectionView.EmptyView results in an Exception on Windows * Test case written and fix slightly modified * Test case modified * Snap added for android and iOS * Test case modified * snap removed * Test case modified * Removed curly braces * Test case modified
github-actions bot
pushed a commit
that referenced
this pull request
Mar 27, 2025
…dows (#28367) * Fixed Using CollectionView.EmptyView results in an Exception on Windows * Test case written and fix slightly modified * Test case modified * Snap added for android and iOS * Test case modified * snap removed * Test case modified * Removed curly braces * Test case modified
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Issue Details:
An exception is thrown when navigating back and forth to a page containing a CollectionView with the EmptyView property set on Windows.
Root Cause:
When navigating from a page containing a CollectionView to a previous page, the CollectionView correctly clears its VirtualView and Handler. Every time when navigate back to the CollectionView page, it properly creates new VirtualView and Handler. However, the VirtualView and Handler for the empty view (which is a Label) are not recreated. Instead, the same empty view is reused and added to the content of the newly created EmptyViewHandler, leading to the exception.
Description of Change:
I invoked the DisconnectHandler method for the form's empty view, which ensures that the VirtualView and its handler, platform view are properly cleared. This change was made in the ItemsViewHandler.Windows.cs class.
Tested the behavior in the following platforms.
Reference:
N/A
Issues Fixed:
Fixes #28212
Screenshots