0
votes

I finally found away (since PushAsync() doesn't work globally) how to navigate to a next page from a MasterDetailPage like so:

Application.Current.MainPage = new NavigationPage(new Screen_Profile());

This opens a new page, but then I cannot go back to the previous page, but this is resetting the navigation stack.

How can I navigate away but still have the option of returning to MasterDetail page navigation?

2
Have you tried to add the MasterDetailPage into a NavigationPage,like MainPage = new NavigationPage(new YourMasterDetailPage ()); in app.csLeo Zhu - MSFT

2 Answers

0
votes

you can try using

 Navigation.PushAsync(new Screen_Profile());

try to read more on this link https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical

0
votes

Here is the reference about the navigation with masterDetailpage

In your App.cs you would have something similar to this code (apologies if it doesn't compile, I am coding this off the top of my head).

public static NavigationPage NavPage = null;

public App()
{
    var _navPage = new NavigationPage(new PageOne());

    var _masterPage = new MasterDetailpage();
    _masterPage.Detail = NavPage;
    _masterPage.Master = (your master / menu page);

    MainPage = _masterPage;

}

Then in your code you can reference

await App.NavPage.PushAsync(new PageTwo());

That gets you functional. However you don't want to access the NavigationPage this way. You can use DependencyInjection to create a NavigationService.

Something like

public class NavigationService: INavigationService
{

      public NavigationService(NavigationPage navPage)
      {
            // Keep local copy of navPage
      }

      public async Task NavigateTo(Page page)
      {

            await _navPage.PushAsync(page);

      }

      public async Task GoBack()
      {

            await _navPage.PopAsync();

      }

}

You should use like this Pattern to navigate.