From a6ce63e8c654aad790ea661aabb35cf2a10dcd4a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 28 Nov 2025 23:16:30 +0000 Subject: [PATCH 1/4] Initial plan From 1cb6b634814ad9330169704f4026d2650955b191 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 28 Nov 2025 23:20:44 +0000 Subject: [PATCH 2/4] Add documentation for Page navigation events (NavigatedTo, NavigatingFrom, NavigatedFrom) Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> --- docs/user-interface/pages/navigationpage.md | 70 ++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/docs/user-interface/pages/navigationpage.md b/docs/user-interface/pages/navigationpage.md index 99c533518..fc8db8fb4 100644 --- a/docs/user-interface/pages/navigationpage.md +++ b/docs/user-interface/pages/navigationpage.md @@ -1,7 +1,7 @@ --- title: "NavigationPage" description: "The .NET MAUI NavigationPage is used to perform hierarchical navigation through a stack of last-in, first-out (LIFO) pages." -ms.date: 09/30/2024 +ms.date: 11/28/2025 --- # NavigationPage @@ -196,6 +196,74 @@ In this example, the current page is removed from the modal stack, with the new On Android, you can always return to the previous page by pressing the standard *Back* button on the device. If the modal page requires a self-contained task to be completed before leaving the page, the app must disable the *Back* button. This can be accomplished by overriding the `Page.OnBackButtonPressed` method on the modal page. +## Page navigation events + +The class defines `NavigatedTo`, `NavigatingFrom`, and `NavigatedFrom` navigation events that are raised during page navigation. The `NavigatingFrom` event is raised when the current page is about to be navigated away from. The `NavigatedFrom` event is raised after the current page has been navigated away from. The `NavigatedTo` event is raised after navigating to the current page. + +> [!NOTE] +> On iOS and Mac Catalyst, these events can be raised before native animation completes when navigating between pages. + +The following event handlers subscribe to the navigation events: + +```csharp +public partial class MainPage : ContentPage +{ + public MainPage() + { + InitializeComponent(); + + NavigatedTo += OnNavigatedTo; + NavigatingFrom += OnNavigatingFrom; + NavigatedFrom += OnNavigatedFrom; + } + + void OnNavigatedTo(object sender, NavigatedToEventArgs args) + { + // Invoked when the page has been navigated to + } + + void OnNavigatingFrom(object sender, NavigatingFromEventArgs args) + { + // Invoked when the page is being navigated away from + } + + void OnNavigatedFrom(object sender, NavigatedFromEventArgs args) + { + // Invoked when the page has been navigated away from + } +} +``` + +Rather than subscribing to the events, a -derived class can override the , , and methods: + +```csharp +public partial class MainPage : ContentPage +{ + protected override void OnNavigatedTo(NavigatedToEventArgs args) + { + base.OnNavigatedTo(args); + + // Invoked when the page has been navigated to + } + + protected override void OnNavigatingFrom(NavigatingFromEventArgs args) + { + base.OnNavigatingFrom(args); + + // Invoked when the page is being navigated away from + } + + protected override void OnNavigatedFrom(NavigatedFromEventArgs args) + { + base.OnNavigatedFrom(args); + + // Invoked when the page has been navigated away from + } +} +``` + +These methods can be overridden to perform work immediately after navigation. For example, in the `OnNavigatedTo` method you might populate a collection of items from a database or web service. + ## Pass data during navigation Sometimes it's necessary for a page to pass data to another page during navigation. Two standard techniques for accomplishing this are passing data through a page constructor, and by setting the new page's `BindingContext` to the data. From d1afb7aa0ee45118224608eea62b4bfa5751098e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 28 Nov 2025 23:44:05 +0000 Subject: [PATCH 3/4] Document .NET 10 navigation event args properties (NavigationType, PreviousPage, DestinationPage) Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> --- docs/user-interface/pages/navigationpage.md | 111 ++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/docs/user-interface/pages/navigationpage.md b/docs/user-interface/pages/navigationpage.md index fc8db8fb4..973392afd 100644 --- a/docs/user-interface/pages/navigationpage.md +++ b/docs/user-interface/pages/navigationpage.md @@ -203,8 +203,71 @@ The class defines `NavigatedTo`, `Navigating > [!NOTE] > On iOS and Mac Catalyst, these events can be raised before native animation completes when navigating between pages. +::: moniker range=">=net-maui-10.0" + +The `NavigatedToEventArgs` class defines the following properties: + +- `PreviousPage`, of type , represents the page that was navigated from. +- `NavigationType`, of type `NavigationType`, represents the type of navigation that occurred. + +The `NavigatingFromEventArgs` class defines the following properties: + +- `DestinationPage`, of type , represents the page being navigated to. +- `NavigationType`, of type `NavigationType`, represents the type of navigation that is occurring. + +The `NavigatedFromEventArgs` class defines the following properties: + +- `DestinationPage`, of type , represents the page that was navigated to. +- `NavigationType`, of type `NavigationType`, represents the type of navigation that occurred. + +The `NavigationType` enumeration defines the following members: + +- `Push`, indicates that a page was pushed onto the navigation stack. +- `Pop`, indicates that a page was popped from the navigation stack. +- `PopToRoot`, indicates that all pages except the root page were popped from the navigation stack. +- `Insert`, indicates that a page was inserted into the navigation stack. +- `Remove`, indicates that a page was removed from the navigation stack. +- `Replace`, indicates that a page was replaced in the navigation stack. + +::: moniker-end + The following event handlers subscribe to the navigation events: +::: moniker range="<=net-maui-9.0" + +```csharp +public partial class MainPage : ContentPage +{ + public MainPage() + { + InitializeComponent(); + + NavigatedTo += OnNavigatedTo; + NavigatingFrom += OnNavigatingFrom; + NavigatedFrom += OnNavigatedFrom; + } + + void OnNavigatedTo(object sender, NavigatedToEventArgs args) + { + // Invoked when the page has been navigated to + } + + void OnNavigatingFrom(object sender, NavigatingFromEventArgs args) + { + // Invoked when the page is being navigated away from + } + + void OnNavigatedFrom(object sender, NavigatedFromEventArgs args) + { + // Invoked when the page has been navigated away from + } +} +``` + +::: moniker-end + +::: moniker range=">=net-maui-10.0" + ```csharp public partial class MainPage : ContentPage { @@ -220,22 +283,32 @@ public partial class MainPage : ContentPage void OnNavigatedTo(object sender, NavigatedToEventArgs args) { // Invoked when the page has been navigated to + Page? previousPage = args.PreviousPage; + NavigationType navigationType = args.NavigationType; } void OnNavigatingFrom(object sender, NavigatingFromEventArgs args) { // Invoked when the page is being navigated away from + Page? destinationPage = args.DestinationPage; + NavigationType navigationType = args.NavigationType; } void OnNavigatedFrom(object sender, NavigatedFromEventArgs args) { // Invoked when the page has been navigated away from + Page? destinationPage = args.DestinationPage; + NavigationType navigationType = args.NavigationType; } } ``` +::: moniker-end + Rather than subscribing to the events, a -derived class can override the , , and methods: +::: moniker range="<=net-maui-9.0" + ```csharp public partial class MainPage : ContentPage { @@ -262,6 +335,44 @@ public partial class MainPage : ContentPage } ``` +::: moniker-end + +::: moniker range=">=net-maui-10.0" + +```csharp +public partial class MainPage : ContentPage +{ + protected override void OnNavigatedTo(NavigatedToEventArgs args) + { + base.OnNavigatedTo(args); + + // Invoked when the page has been navigated to + Page? previousPage = args.PreviousPage; + NavigationType navigationType = args.NavigationType; + } + + protected override void OnNavigatingFrom(NavigatingFromEventArgs args) + { + base.OnNavigatingFrom(args); + + // Invoked when the page is being navigated away from + Page? destinationPage = args.DestinationPage; + NavigationType navigationType = args.NavigationType; + } + + protected override void OnNavigatedFrom(NavigatedFromEventArgs args) + { + base.OnNavigatedFrom(args); + + // Invoked when the page has been navigated away from + Page? destinationPage = args.DestinationPage; + NavigationType navigationType = args.NavigationType; + } +} +``` + +::: moniker-end + These methods can be overridden to perform work immediately after navigation. For example, in the `OnNavigatedTo` method you might populate a collection of items from a database or web service. ## Pass data during navigation From 6761a3e7410b0872ffd59023fe9e214fb16ef02c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 28 Nov 2025 23:45:49 +0000 Subject: [PATCH 4/4] Fix code review feedback: use xref markup for NavigationType, improve example intro text Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> --- docs/user-interface/pages/navigationpage.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/user-interface/pages/navigationpage.md b/docs/user-interface/pages/navigationpage.md index 973392afd..5810654aa 100644 --- a/docs/user-interface/pages/navigationpage.md +++ b/docs/user-interface/pages/navigationpage.md @@ -208,19 +208,19 @@ The class defines `NavigatedTo`, `Navigating The `NavigatedToEventArgs` class defines the following properties: - `PreviousPage`, of type , represents the page that was navigated from. -- `NavigationType`, of type `NavigationType`, represents the type of navigation that occurred. +- `NavigationType`, of type , represents the type of navigation that occurred. The `NavigatingFromEventArgs` class defines the following properties: - `DestinationPage`, of type , represents the page being navigated to. -- `NavigationType`, of type `NavigationType`, represents the type of navigation that is occurring. +- `NavigationType`, of type , represents the type of navigation that is occurring. The `NavigatedFromEventArgs` class defines the following properties: - `DestinationPage`, of type , represents the page that was navigated to. -- `NavigationType`, of type `NavigationType`, represents the type of navigation that occurred. +- `NavigationType`, of type , represents the type of navigation that occurred. -The `NavigationType` enumeration defines the following members: +The enumeration defines the following members: - `Push`, indicates that a page was pushed onto the navigation stack. - `Pop`, indicates that a page was popped from the navigation stack. @@ -231,7 +231,7 @@ The `NavigationType` enumeration defines the following members: ::: moniker-end -The following event handlers subscribe to the navigation events: +The following example shows how to subscribe to the navigation events: ::: moniker range="<=net-maui-9.0"