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.
Xamarin. Forms will continue to receive service releases through November 2022.
Xamarin. Forms provide three common navigation patterns (NavigationPage, TabbedPage, and CarouselPage) for your use.
Xamarin.Forms
supports multiple navigation hosts built-in:
NavigationPage
, where the next page slide in,TabbedPage
, the one you don't likeCarouselPage
, 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.
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 ());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With