Description
When removing pages from a NavigationPage's navigation stack, using NavigationPage.Navigation.RemovePage() fails to properly disconnect handlers from the removed pages, while using ContentPage.Navigation.RemovePage() correctly disconnects handlers as expected.
Expected Behavior
When a page is removed from the navigation stack using RemovePage(), its handler should be disconnected regardless of whether you access the Navigation property through the NavigationPage or ContentPage.
Actual Behavior
- Button_OnClicked2 (correct behavior): Uses
ContentPage.Navigation.RemovePage() → handlers are properly disconnected from removed pages
- Button_OnClicked (bug): Uses
NavigationPage.Navigation.RemovePage() → handlers remain connected to removed pages, preventing proper cleanup
Code Example
// This FAILS to disconnect handlers (BUG)
private void Button_OnClicked(object? sender, EventArgs e)
{
var navigationPage = Shell.Current.Navigation.ModalStack
.FirstOrDefault(p => p is NavigationPage) as NavigationPage;
var stack = navigationPage.Navigation.NavigationStack;
var pages = stack.Take(stack.Count - 1).ToList();
foreach (var page in pages)
{
navigationPage.Navigation.RemovePage(page); // Handlers stay connected
}
Navigation.PopModalAsync();
}
// This correctly disconnects handlers (Expected behavior)
private void Button_OnClicked2(object? sender, EventArgs e)
{
var pages = Navigation.NavigationStack.Take(Navigation.NavigationStack.Count - 1).ToList();
foreach (var page in pages)
{
Navigation.RemovePage(page); // Handlers are properly disconnected
}
Navigation.PopModalAsync();
}

Steps to Reproduce
- Clone https://github.com/Vetle444/MauiTestApp/tree/popModalHandler
- Make sure to use branch
popModalHandler
- Run app
- Click button
Test Page Modal
- Click button
Navigate to test page 2
- Click button
Pop modal using NavigationPage
- Observe that no dialog appears describing that the root page was disconnected
- Now try popping modal using the other button
- Observe that the dialog appears
Link to public reproduction project repository
https://github.com/Vetle444/MauiTestApp/tree/popModalHandler
Version with bug
9.0.110 SR12
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
No response
Affected platforms
iOS, Android, macOS, Windows
Affected platform versions
No response
Did you find any workaround?
Make sure to call .DisconnectHandlers after removing the page
Relevant log output
Description
When removing pages from a NavigationPage's navigation stack, using
NavigationPage.Navigation.RemovePage()fails to properly disconnect handlers from the removed pages, while usingContentPage.Navigation.RemovePage()correctly disconnects handlers as expected.Expected Behavior
When a page is removed from the navigation stack using
RemovePage(), its handler should be disconnected regardless of whether you access the Navigation property through the NavigationPage or ContentPage.Actual Behavior
ContentPage.Navigation.RemovePage()→ handlers are properly disconnected from removed pagesNavigationPage.Navigation.RemovePage()→ handlers remain connected to removed pages, preventing proper cleanupCode Example
Steps to Reproduce
popModalHandlerTest Page ModalNavigate to test page 2Pop modal using NavigationPageLink to public reproduction project repository
https://github.com/Vetle444/MauiTestApp/tree/popModalHandler
Version with bug
9.0.110 SR12
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
No response
Affected platforms
iOS, Android, macOS, Windows
Affected platform versions
No response
Did you find any workaround?
Make sure to call .DisconnectHandlers after removing the page
Relevant log output