MainPage = new NavigationPage(new MyFirstContentPage());
Now you have you stack.
After this, you can PushAsync(new MySecondContentPage());
That’s all folks
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am relatively new to Xamarin.Forms, and am trying to figure out how to programmatically navigate between pages. My app only has 2 pages, so I do not need any complex hierarchy or organization, just a simple back and forth. I have found the following page:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation
But it seems like there is an excessively large & complex amount of code involved to do something as simple as navigate to another page. Is it really necessary to do that much work just to navigate to another page? In UWP, there was a simple Navigate method, I was hoping for something similar to that. Is there any easy way to navigate between pages without doing any major preparation like the link above?
MainPage = new NavigationPage(new MyFirstContentPage());
Now you have you stack.
After this, you can PushAsync(new MySecondContentPage());
That’s all folks
I had looked at that also, and I had some trouble understanding that as well. It mentions a stack, as well as the NavigationPage. First of all, I do not want any kind of organization or history (the stack), I just want to be able to say "take me to this page". Also, what exactly is NavigationPage? It sounds to me like NavigationPage is being used in place of ContentPage, but I do not want to change the look of my page, I want the navigation to be completely programmatic.
Thanks! For anyone reading this that wants to know exactly what I changed, I made the following changes:
In the constructor of my App class (App.xaml.cs):
MainPage = new MainPage();
Replaced with:
MainPage = new NavigationPage(new MainPage());
Code to go from MainPage.xaml to Settings.xaml:
Navigation.PushAsync(new Settings());
Code to return from Settings.xaml back to MainPage.xaml:
Navigation.PopToRootAsync();
I also added the following to the ContentPage element in my MainPage.xaml & Settings.xaml files (you may or may not want this):
NavigationPage.HasNavigationBar="False"
Thanks again, and hopefully this can help others as well!