MasterDetailPage & NavigationPage RRS feed

  • Question

  • User224626 posted


    I try to implement a Navigation using the MasterDetailPage.

    This code is used in my App.cs:

    public static NavigationPage Navigation;
    public App()
        Navigation = new NavigationPage(new MainView());
       var mdPage = new MasterDetailPage();
       mdPage.Detail = Navigation;
       mdPage.Master = new NavigationView();
       MainPage = mdPage;

    On the first page (MainView) the MD is working fine. But when I click a link on my MasterPage (NavigationView) with the following code:

    async void onNextPageClick()
        await App.Navigation.PushAsync(new DemoView());

    the DemoView shows correctly up, but my MD-Page in the navigationbar turned in a functional back button and the MasterPage won't close automatically.

    Could anyone help please?

    Friday, May 13, 2016 6:52 AM


  • User174299 posted


    this behaviour is intended by the navigation page. If you push a page on the stack (call PushAsync) the menu button changes to a back button. Pressing this back button allows the user to return to the previous page of the navigation.

    However, if you do not want this to happen, you have to replace your previous navigation page with a new one. mdPage.Detail = new NavigationPage(new DemoView()); Replacing the root page of the NavigationPage might be another solution, but I am not sure if this is possible.

    If you want to hide the master just set IsPresented of the masterdetailpage to false: mdPage.IsPresented = false;

    The method "onNextPageClick" seems to be in the NavigationView so you won't have a reference to your mdPage. Just call something like var masterDetailPage = App.Current.MainPage as MasterDetailPage; to get the reference and continue with the commands stated above masterDetailPage.Detail = new NavigationPage(new DemoView()); masterDetailPage.IsPresented = false;

    Hope this helps :smile:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 13, 2016 7:50 AM