Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Page Navigation under Windows Phone

$
0
0

Hello. I have the following problem:

I want to navigate from my ROOT page to PAGE A and then from PAGE A to PAGE B but without keeping PAGE A in the navigation stack.
I was able to achieve it by moving the logic to a class Navigator with static method, performing:

// App.cs
// GetMainPage() - Setting Navigator.NavigationContext to my NavigationPage

// Navigator.cs
public static NavigationPage NavigationContext;
...
public static async void PopToRootAndPush(Type pageType)
{
        await NavigationContext.Navigation.PopToRootAsync();
        await NavigationContext.Navigation.PushAsync(Activator.CreateInstance(pageType) as MyBasePage);
}

// PageA.cs
// Calling Navigator.PopToRootAndPush(typeof(PageB));

Everything is working as expected on Android and iOS but NOT on Windows Phone.
(ANDROID - OK) Order of events for the navigation from the picture above:

*Application started*
Root Constructor
Root OnAppearing
*We are on Root Page now*
*Open PageA clicked*
PageA Constructor
PageA OnAppearing
Root OnDisappearing
*We are on PageA now*
*Open PageB clicked*
PageB Constructor
Root OnAppearing
PageA OnDisappearing
PageB OnAppearing
Root OnDisappearing
*We are on PageB now*

(WINDOWS PHONE - NOT OK) Order of events for the navigation from the picture above:

*Application started*
Root Constructor
Root OnAppearing
*We are on Root Page now*
*Open PageA clicked*
PageA Constructor
Root OnDisappearing  <- ???
PageA OnAppearing  <- ???
*We are on PageA now*
*Open PageB clicked*
PageB Constructor
PageB OnAppearing
PageA OnDisappearing  <- ???
Root OnAppearing  <- ???
*We are on Root Page now* // PageB stays under Root...
  1. How can I navigate the way I need to (the picture above)?
  2. Why is WP navigation behaviour different?
  3. Bonus question: Can I make a custom PageNavigation Renderer for WP? NavigationPageRenderer doesn't provide any methods to override (like OnPopViewAsync/OnPushAsync from NavigationRenderer in Android). If I want to remove the page navigation animation in WP, how am I supposed to do that?

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>