Skip to content Skip to sidebar Skip to footer

Is It There An Alternative To Navigation For Xamarin?

I working on an Android App using Xamarin.Forms. I have a few problems with the navigation. When I use Navigation.PushAsync(new ContentPage()); my navigation flow creates bucles. W

Solution 1:

I believe what you are trying to do is "manipulating the navigation stack".

  • If you don't want a page to be on the navigation stack you can remove it as soon as you navigate away from it using Navigation.RemovePage(page). You can pass a saved reference of that page, or look it up in the Navigation.NavigationStack, if it's a known scenario (known navigation stack index of the page you want to remove) you can do:

    Navigation.RemovePage(Navigation.NavigationStack[index]);

  • Or you can use InsertPageBefore() followed by a PopAsync() as shown in the navigation docs example:

These methods enable a custom navigation experience, such as replacing a login page with a new page, following a successful login. The following code example demonstrates this scenario:

asyncvoidOnLoginButtonClicked(object sender, EventArgs e)
{
  if (IsValid)
  {
    Navigation.InsertPageBefore(new MainPage (), this);
    await Navigation.PopAsync();
  }

 else
 {
    // Login failed
  }
}

Solution 2:

You shouldn't use navigation like this. Some forms (especially login), should be popped when completed.

  1. Push login form
  2. User Completes login
  3. Pop login form
  4. Decide which form should be pushed next.

Solution 3:

In your scenario I suggest you use Modal Pages to present the login page .

It will create an extra modal stack which will not affect the original stack.

When user complete login , then pop the login page .


The flow

  • Set NavigationPage(root page : Main) as MainPage in App.
  • Show login page using PushModalAsync .
  • Complete login
  • Close login page using PopModalAsync.

Solution 4:

From any activity page you can open another page using

StartActivity(typeof(YourView));

When that page finishes, it returns you to the page that you called it from.

Post a Comment for "Is It There An Alternative To Navigation For Xamarin?"