-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[windows] Fixed Rapid change of selected tab results in crash. #33113
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
base: main
Are you sure you want to change the base?
[windows] Fixed Rapid change of selected tab results in crash. #33113
Conversation
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 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
_displayedPagetracking field to prevent redundant navigation and track which MAUI Page is currently displayed - Added content detachment logic in
NavigateToPageto explicitly clear the previous WinUI Page's ContentPresenter before navigation - Added guard condition in
UpdateCurrentPageContentto 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) |
Copilot
AI
Dec 11, 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 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.
Root Cause
On Windows,
TabbedPageuses WinUIFramenavigation to display each tab’s content. Each tab’s platform view (native UI element) is hosted inside a WinUIPagethrough aContentPresenter.During rapid tab switching, the platform view is reassigned to a new WinUI
Pagewhile 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
_displayedPagetracking field to maintain the correct displayed MAUI Page during navigation, allowingNavigateToPageto skip early if the requested page is already displayed and avoid redundant navigation. The method also now clears the previous WinUI Page’sContentPresenterto explicitly detach the platform view and prevent the “element already has a parent” WinUI error. InUpdateCurrentPageContent, a skip guard avoids reassigning content that is already set, while_displayedPageis updated only after successful content assignment. Finally, OnHandlerDisconnected resets_displayedPageto null to ensure proper cleanup and prevent stale references.Issues Fixed
Fixes #32824
Tested the behaviour in the following platforms
Output Video