Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you switch pages in Xamarin.Forms?

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.

like image 306
Eric Avatar asked Aug 06 '14 16:08

Eric


People also ask

Is Xamarin form dying?

Xamarin. Forms will continue to receive service releases through November 2022.

What are the pages in Xamarin forms?

Xamarin. Forms provide three common navigation patterns (NavigationPage, TabbedPage, and CarouselPage) for your use.


2 Answers

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.

like image 152
Stephane Delcroix Avatar answered Jan 18 '23 18:01

Stephane Delcroix


In the App class you can set the MainPage to a Navigation Page and set the root page to your ContentPage:

public App () {     // The root page of your application     MainPage = new NavigationPage( new FirstContentPage() ); } 

Then in your first ContentPage call:

Navigation.PushAsync (new SecondContentPage ()); 
like image 40
David Douglas Avatar answered Jan 18 '23 16:01

David Douglas