Skip to content

Conversation

@praveenkumarkarunanithi
Copy link
Contributor

Root Cause

On Windows, TabbedPage uses WinUI Frame navigation to display each tab’s content. Each tab’s platform view (native UI element) is hosted inside a WinUI Page through a ContentPresenter.
During rapid tab switching, the platform view is reassigned to a new WinUI Page while still attached to the previous one. WinUI does not allow a UI element to exist in two visual trees simultaneously, which causes the crash.

Description of Change

Added a _displayedPage tracking field to maintain the correct displayed MAUI Page during navigation, allowing NavigateToPage to skip early if the requested page is already displayed and avoid redundant navigation. The method also now clears the previous WinUI Page’s ContentPresenter to explicitly detach the platform view and prevent the “element already has a parent” WinUI error. In UpdateCurrentPageContent, a skip guard avoids reassigning content that is already set, while _displayedPage is updated only after successful content assignment. Finally, OnHandlerDisconnected resets _displayedPage to null to ensure proper cleanup and prevent stale references.

Issues Fixed

Fixes #32824

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output Video

Before Issue Fix After Issue Fix
withoutfix withfix

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 11, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review December 11, 2025 13:35
Copilot AI review requested due to automatic review settings December 11, 2025 13:35
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 pull request fixes a Windows-specific crash in TabbedPage when rapidly switching between tabs. The crash occurred because during rapid tab switches, platform views were being reassigned to new WinUI Pages while still attached to previous ones, violating WinUI's constraint that a UI element cannot exist in multiple visual trees simultaneously.

Key Changes

  • Added _displayedPage tracking field to prevent redundant navigation and track which MAUI Page is currently displayed
  • Added content detachment logic in NavigateToPage to explicitly clear the previous WinUI Page's ContentPresenter before navigation
  • Added guard condition in UpdateCurrentPageContent to skip updates when the requested page is already displayed

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs Implements the fix by adding _displayedPage field, clearing old content before navigation, and adding guard conditions to prevent redundant updates
src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs Adds regression test to verify old ContentPresenter content is cleared during tab switches

await CreateHandlerAndAddToWindow<TabbedViewHandler>(tabbedPage, handler =>
{
var frame = typeof(TabbedPage)
.GetField("_navigationFrame", BindingFlags.NonPublic | BindingFlags.Instance)
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code uses BindingFlags but the required using directive for System.Reflection is missing from the file. This will cause a compilation error. Add 'using System.Reflection;' to the top of the file with the other using statements.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-tabbedpage TabbedPage community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rapid change of selected tab results in crash on Windows.

2 participants