Master-Detail Page as a Navigation drawer?

mshwfmshwf EGMember ✭✭✭
edited January 23 in Xamarin.Forms

I need a side navigation drawer in the application, the functionality provided by the Master-Detail Page is not compatible with my needs,
I need to have the drawer in the MainPage only and to behave like a NavigationPage: when any item in the master page is clicked, then replacing the hamburger button with a back button that navigate to the previous page.. is it possible with the Xamarin's Master-Detail page?

What I've tried so far:

  • setting
    MainPage = new NavigationPage(new MainPage()); //where MainPage is a MasterDetailPage

then set the NavigationPage.HasNavigationBar of the main page to False.

but I have two initial problems:
1- the title is beneath the back button.
2- when I navigate back, the menu is still opened.

There might be another problems of this workaround, that I'm not aware of at the moment

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    1- the title is beneath the back button.

    What title ? Could you attach the screen shot ?

    2- when I navigate back, the menu is still opened.

    To close it use MasterDetailPage.IsPresented = false;

  • mshwfmshwf EGMember ✭✭✭
    edited January 25

    Thanks for your reply, I found that this caused the first problem:

    Navigation.PushAsync( new NavigationPage((Page)Activator.CreateInstance(item.TargetType)));
    


    replaced with this and fixed it:

    Navigation.PushAsync((Page)Activator.CreateInstance(item.TargetType));
    

    for point 2:
    the click handlers for the master page items lie in the maser page not the MasterDetailPage, so I don't have access to the IsPresented property. is it still possible to hide it?

    Also I need to know, is my approach a common use of the master detail page in Xamarin, the official documentation states that:

    The Xamarin.Forms MasterDetailPage is a page that manages two related pages of information – a master page that presents items, and a detail page that presents details about items on the master page

    I'm using it for a different approach: to navigate through the different pages in the application. I need to make sure I won't fall in troubles due to my approach. We used to use 3rd party libraries to manage this functionality (Syncfusion Navigation drawer for example), but I wanted to use the built in solutions as possible to reduce the dependency of 3rd party libraries.
    Thanks

Sign In or Register to comment.