Loosen AvaloniaContentPage to AvaloniaPage for TabbedPage/StackedNavigation#221
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses runtime InvalidCastException failures when NavigationPage stacks or TabbedPage children contain non-ContentPage page types (e.g., TabbedPage, nested NavigationPage), by loosening platform wrapping/casting to the common Avalonia Page base type. This aligns the Avalonia platform layer with MAUI’s behavior where navigation stacks and tabs can host any Page, not just ContentPage.
Changes:
- Updated
StackNavigationManager.WrapPage(and related stack sync structures) to useAvalonia.Controls.Pageinstead ofAvalonia.Controls.ContentPage. - Updated
TabbedPageExtensions.UpdateChildrento wrap tab children asAvalonia.Controls.Pageinstead ofContentPage, avoiding invalid casts. - Added tests covering
TabbedPagechildren that areNavigationPage/nestedTabbedPage, and pushing aTabbedPageonto aNavigationPagestack.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Avalonia.Controls.Maui.Tests/Handlers/TabbedPageHandlerTests.cs | Adds test coverage for mixed tab child page types (Content/Navigation/Tabbed). |
| tests/Avalonia.Controls.Maui.Tests/Handlers/NavigationPageHandlerTests.cs | Adds regression tests ensuring TabbedPage can be pushed/used in navigation stacks. |
| src/Avalonia.Controls.Maui/Platform/StackNavigationManager.cs | Broadens wrapping from ContentPage to Page to support more MAUI page types in the stack. |
| src/Avalonia.Controls.Maui/Handlers/Shell/ShellStackNavigationManager.cs | Updates the override signature to match the base WrapPage return type change. |
| src/Avalonia.Controls.Maui/Extensions/TabbedPageExtensions.cs | Broadens wrapping from ContentPage to Page for tab children to avoid invalid casts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #215
TabbedPage and StackedNavigation were too strict in guarding what was supported. It should be a base-level
AvaloniaPage.