Basic Page Navigation in Xamarin.Forms

Nathan Sokalski 4,116 Reputation points
2020-12-13T02:14:52.947+00:00

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?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
0 comments No comments
{count} votes

3 additional answers

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points
    2020-12-13T07:18:17.177+00:00
    0 comments No comments

  2. Nathan Sokalski 4,116 Reputation points
    2020-12-13T17:34:42.163+00:00

    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.

    0 comments No comments

  3. Nathan Sokalski 4,116 Reputation points
    2020-12-14T01:14:48.797+00:00

    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!

    0 comments No comments