Skip to content

Loosen AvaloniaContentPage to AvaloniaPage for TabbedPage/StackedNavigation#221

Merged
drasticactions merged 3 commits into
mainfrom
dev/timill/cast-page
Jun 16, 2026
Merged

Loosen AvaloniaContentPage to AvaloniaPage for TabbedPage/StackedNavigation#221
drasticactions merged 3 commits into
mainfrom
dev/timill/cast-page

Conversation

@drasticactions

Copy link
Copy Markdown
Collaborator

Fixes #215

TabbedPage and StackedNavigation were too strict in guarding what was supported. It should be a base-level AvaloniaPage.

Copilot AI review requested due to automatic review settings June 15, 2026 07:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 use Avalonia.Controls.Page instead of Avalonia.Controls.ContentPage.
  • Updated TabbedPageExtensions.UpdateChildren to wrap tab children as Avalonia.Controls.Page instead of ContentPage, avoiding invalid casts.
  • Added tests covering TabbedPage children that are NavigationPage/nested TabbedPage, and pushing a TabbedPage onto a NavigationPage stack.

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.

Comment thread src/Avalonia.Controls.Maui/Platform/StackNavigationManager.cs
@drasticactions drasticactions merged commit 850ae7a into main Jun 16, 2026
12 checks passed
@drasticactions drasticactions deleted the dev/timill/cast-page branch June 16, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidCastException in StackNavigationManager.WrapPage and TabbedPageExtensions.UpdateChildren

2 participants