Skip to content

Conversation

@KarthikRajaKalaimani
Copy link
Contributor

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.

  • Android
  • Windows
  • iOS
  • Mac

Reference:

N/A

Issues Fixed:

Fixes #28212

Screenshots

Before
419837923-ab67452f-a7d6-4d9b-96b6-1baef109ebcb
After
2025-03-1312-02-02-ezgif com-video-to-gif-converter

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 13, 2025
@dotnet-policy-service
Copy link
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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 13, 2025
@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Mar 13, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@KarthikRajaKalaimani KarthikRajaKalaimani marked this pull request as ready for review March 14, 2025 05:28
Copilot AI review requested due to automatic review settings March 14, 2025 05:28
@KarthikRajaKalaimani KarthikRajaKalaimani requested a review from a team as a code owner March 14, 2025 05:28
Copy link
Contributor

Copilot AI left a 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; } = [];
Copy link

Copilot AI Mar 14, 2025

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.

Suggested change
public ObservableCollection<string> Items { get; } = [];
public ObservableCollection<string> Items { get; } = new ObservableCollection<string>();

Copilot uses AI. Check for mistakes.
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Member

Do we also need to call ? ItemsView.RemoveLogicalChild(_formsEmptyView);

@PureWeen PureWeen changed the base branch from main to inflight/current March 18, 2025 18:21
@PureWeen PureWeen merged commit 6bb1182 into dotnet:inflight/current Mar 18, 2025
127 of 129 checks passed
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
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using CollectionView.EmptyView results in an Exception on Windows

4 participants