How do you switch pages in Xamarin.Forms?

Eric picture Eric · Aug 6, 2014 · Viewed 160.8k times · Source

How do you switch between pages in Xamarin Forms?

My main page is a ContentPage and I don't want to switch to something like a Tabbed Page.

I've been able to pseudo-do it by finding parents of the controls that should trigger the new page until I find the ContentPage and then swap out the Content with controls for a new page. But this seems really sloppy.

Answer

Stephane Delcroix picture Stephane Delcroix · Aug 6, 2014

Xamarin.Forms supports multiple navigation hosts built-in:

  • NavigationPage, where the next page slide in,
  • TabbedPage, the one you don't like
  • CarouselPage, that allows for switching left and right to next/prev pages.

On top of this, all pages also supports PushModalAsync() which just push a new page on top of the existing one.

At the very end, if you want to make sure the user can't get back to the previous page (using a gesture or the back hardware button), you can keep the same Page displayed and replace its Content.

The suggested options of replacing the root page works as well, but you'll have to handle that differently for each platform.