Added OnNavigatingFrom extension for popup related navigation #3099
Added OnNavigatingFrom extension for popup related navigation #3099dartasen wants to merge 5 commits intoCommunityToolkit:mainfrom
Conversation
There was a problem hiding this comment.
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.cswithIsDestinationPageACommunityToolkitPopupPage()extension method - Updated documentation in
NavigatedFromEventArgsExtensions.shared.csfor consistency - Added comprehensive unit tests in
NavigatingFromEventArgsExtensionsTests.cswith 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 |
src/CommunityToolkit.Maui.UnitTests/Extensions/NavigatingFromEventArgsExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Extensions/NavigatingFromEventArgsExtensionsTests.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui/Extensions/NavigatedFromEventArgsExtensions.shared.cs
Outdated
Show resolved
Hide resolved
TheCodeTraveler
left a comment
There was a problem hiding this comment.
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!
|
Thank's @TheCodeTraveler, will look at adding the documentation tomorrow ! However what's the approach you wanna take here ? |
|
Added the documentation 😄 |
Oh wow - strange! Yea, you're totally right. This is a bug in .NET MAUI: I confirmed that the unit test is accurate. I also implemented Screenshots of BugHere's two screenshots showing a breakpoint triggering when I display
And here's a GIF demonstrating that we are correctly navigating to a Next StepsIn 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 🙌 |



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
OnNavigatingFromEventArgsseems to provide a wrongDestinationPageargument. 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
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information