1
votes

How should I use the rootpage correctly so I can navigate/pushasync to other pages with the correct navigatiobar.

Right now It looks like this:

MainPage = new RootPage ();

And my rootpage:

public RootPage ()
    {

        var theMenu = new MenuPage (this);
        theMenu.Title = "::";

        Master = theMenu;

        NavigationPage page = new NavigationPage(new StartPage ());
        Detail = page;
    }

If i have it like this, i get an error when I try to navigate to a new page:

async void contactClick (object s, EventArgs e)
    {
        await Navigation.PushAsync (new ContactPage());
    }

Error: "PushAsync is not supported globally on iOS, please use a NavigationPage."

If i instead do :

MainPage = new NavigationPage (new RootPage ());

I get two navigationbars. I solved it by using...:

NavigationPage.SetHasNavigationBar (this, false);

...on my RootPage but that gives it a weird animation when I navigate to new pages and also it crashes on android. Any ideas how you would solve this?

2

2 Answers

3
votes

As far as I understand you have MasterDetailPage and you want to perform navigation on Detail page.

If so, you should push/pop pages via Detail.Navigation.Push/Popasync(..) (your Detail page is already NavigationPage).


async void contactClick (object s, EventArgs e)
    {
        await Navigation.PushAsync (new ContactPage());
    }

If this method is in MenuPage or RootPage then you got

Error: "PushAsync is not supported globally on iOS, please use a NavigationPage."

because this pages are not NavigationPages.

EDIT: if you want to hide menu after navigation, set RootPage.IsPresented property to false.