Skip to content

Added OnNavigatingFrom extension for popup related navigation #3099

Draft
dartasen wants to merge 5 commits intoCommunityToolkit:mainfrom
dartasen:feat/addnavigatingextension
Draft

Added OnNavigatingFrom extension for popup related navigation #3099
dartasen wants to merge 5 commits intoCommunityToolkit:mainfrom
dartasen:feat/addnavigatingextension

Conversation

@dartasen
Copy link

@dartasen dartasen commented Feb 16, 2026

Description of Change

Added an extension method to OnNavigatingFrom event which checks if the destination page is a popup and if so returns true.

Currently one of the test is failing because MAUI OnNavigatingFromEventArgs seems to provide a wrong DestinationPage argument. Rather than acting like OnNavigatedFrom, it gives the CurrentPage rather than the real navigation destination.

I opened an issue : dotnet/maui#34073

Linked Issues

PR Checklist

Additional information

Copilot AI review requested due to automatic review settings February 16, 2026 11:05
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 adds an extension method for the OnNavigatingFrom navigation event to detect when navigation is transitioning to a Community Toolkit Popup. The implementation mirrors the existing NavigatedFromEventArgsExtensions but operates during the "navigating" phase rather than the "navigated" phase, allowing developers to detect popup navigation before it completes.

Changes:

  • Added NavigatingFromEventArgsExtensions.shared.cs with IsDestinationPageACommunityToolkitPopupPage() extension method
  • Updated documentation in NavigatedFromEventArgsExtensions.shared.cs for consistency
  • Added comprehensive unit tests in NavigatingFromEventArgsExtensionsTests.cs with positive and negative test cases

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
NavigatingFromEventArgsExtensions.shared.cs New extension class providing IsDestinationPageACommunityToolkitPopupPage() method to detect popup navigation during the navigating phase
NavigatedFromEventArgsExtensions.shared.cs Updated documentation comments to use "if" instead of "whether" for consistency with the new extension method
NavigatingFromEventArgsExtensionsTests.cs Added unit tests covering both true and false cases for popup detection during navigation

Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

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

Thanks @dartasen!! Approved ✅

Could you please also open a Docs PR on our official documentation repo? https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Once the Docs PR is submitted, I can merge the code here. I plan on releasing CommunityToolkit.Maui v14.0.1 this week once Microsoft.Maui.Controls v10.0.41 is released. If you're able to get the Docs PR in before Friday, we'll include this in the scheduled release and publish it as CommunityToolkit.Maui v14.1.0 instead!

@TheCodeTraveler TheCodeTraveler added the approved This Proposal has been approved and is ready to be added to the Toolkit label Feb 17, 2026
@dartasen
Copy link
Author

Thank's @TheCodeTraveler, will look at adding the documentation tomorrow !

However what's the approach you wanna take here ?
Currently the UnitTests are failing until OnNavigatingFrom get fixes in MAUI.
Should I remove them and file an issue to add them back as soon as it's fixed ?

@dartasen
Copy link
Author

Added the documentation 😄

@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Feb 18, 2026

Currently the UnitTests are failing until dotnet/maui#34073 get fixes in MAUI

Oh wow - strange! Yea, you're totally right. This is a bug in .NET MAUI: NavigatingFromEventArgs.DestinationPage is actually providing the previous page. Testing it alongside NavigatedFromEventArgs.DestinationPage, we confirm that NavigatingFromEventArgs.DestinationPage provides the destination page.

I confirmed that the unit test is accurate. I also implemented OnNavigatingFrom in the Sample app to confirm it wasn't just a bad test.

Screenshots of Bug

Here's two screenshots showing a breakpoint triggering when I display SimplePopup from our Popups Page in the sample app:

NavigatingFromEventArgs.DestinationPage Incorrect NavigatedFromEventArgs.DestinationPage Incorrect

And here's a GIF demonstrating that we are correctly navigating to a PopupPage but NavigatingFromEventArgs is proving the incorrect value its DestinationPage property.

ScreenFlow

Next Steps

In the meantime, I'll convert this PR to a draft and keep an eye on the Issue you opened. Once that Issue is fixed, we'll merge this PR 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This Proposal has been approved and is ready to be added to the Toolkit blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants