-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed - Using CollectionView.EmptyView results in an Exception on Windows #28367
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
Fixed - Using CollectionView.EmptyView results in an Exception on Windows #28367
Conversation
|
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. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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.
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; } = []; |
Copilot
AI
Mar 14, 2025
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.
The syntax '[]' is not a valid way to initialize an ObservableCollection in C#. Replace it with 'new ObservableCollection();' to correctly instantiate the collection.
| public ObservableCollection<string> Items { get; } = []; | |
| public ObservableCollection<string> Items { get; } = new ObservableCollection<string>(); |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Do we also need to call ? ItemsView.RemoveLogicalChild(_formsEmptyView); |
…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
…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
…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
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