Skip to content

OnNavigatingFrom is reporting wrong DestinationPage #34073

@dartasen

Description

@dartasen

Description

As per .NET MAUI 10, NavigatingFromEventArgs & NavigatedFromEventArgs now gives access to both DestinationPage and NavigationType.

OnNavigatedFrom behaves well, however OnNavigatingFrom will always fill current page as DestinationPage argument.

Example :

Using Shell, navigating From PageA to PageB :

02-16 12:20:07.669 I/DOTNET  (15127): [PageA]::OnNavigatingFrom : Destination: 'PageA', NavigationType: 'PopToRoot'
02-16 12:20:08.039 I/DOTNET  (15127): [PageA]::OnNavigatedFrom : Destination: 'PageB', NavigationType: 'PopToRoot'
02-16 12:20:08.047 I/DOTNET  (15127): [PageB]::OnNavigatedTo : Previous: 'PageA', NavigationType: 'PopToRoot'

PageB to PageA:

02-16 12:23:11.231 I/DOTNET  (15127): [PageB]::OnNavigatingFrom : Destination: 'PageB', NavigationType: 'Push'
02-16 12:23:11.678 I/DOTNET  (15127): [PageB]::OnNavigatedFrom : Destination: 'PageA', NavigationType: 'Push'
02-16 12:23:11.680 I/DOTNET  (15127): [PageA]::OnNavigatedTo : Previous: 'PageB', NavigationType: 'Push'

Steps to Reproduce

  1. Create a new .NET MAUI App that uses Shell
  2. Register two page (Page A and Page B)
  3. Add logging on the pages :
protected override void OnNavigatingFrom(NavigatingFromEventArgs args)
{
    Debug.WriteLine($"[{GetType().Name}]::OnNavigatingFrom : Destination: '{args.DestinationPage?.GetType().Name ?? "null"}', NavigationType: '{args.NavigationType}'");
}

protected override void OnNavigatedFrom(NavigatedFromEventArgs args)
{
    Debug.WriteLine($"[{GetType().Name}]::OnNavigatedFrom : Destination: '{args.DestinationPage?.GetType().Name ?? "null"}', NavigationType: '{args.NavigationType}'");
}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
    Debug.WriteLine($"[{GetType().Name}]::OnNavigatedTo : Previous: '{args.PreviousPage?.GetType().Name ?? "null"}', NavigationType: '{args.NavigationType}'");
}
  1. Navigate from PageA to PageB => logs should show OnNavigating DestinationPage == A while OnNavigated DestinationPage == B
  2. Navigate from PageB to PageA => logs should show OnNavigating DestinationPage == B while OnNavigated DestinationPage == A

Link to public reproduction project repository

No response

Version with bug

10.0.40

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

Use OnNavigated instead of OnNavigating but the lifecycle timings are not the same. OnNavigating is way more early in the navigation lifecycle, which is suitable for particular scenario.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions