Search code examples
xamarinnavigation-drawermaster-detail

Xamarin Form: MasterDetailPage: Does the detail page have to be NavigationPage as a standard


In the sample code from Xamarin website, the Detail page was added to a NavigationPage

Detail = new NavigationPage(new TestPage());

Does TestPage have to be wrapped by NavigationPage? If I remove NavigationPage and just put new TestPage(), it will work on me. If I keep NavigationPage in, I have the error which I have posted in here.

Reference from my other post

If without NavigationPage, the hamburger icon will be gone, even though still able to show the master page.


Solution

  • From official Xamarin documentation:

    Public Constructors
    
    NavigationPage()
    Initializes a new NavigationPage object.
    
    NavigationPage(Page) 
    Creates a new NavigationPage element with root as its root element.
    

    So you only need/want/have to pass a page as argument if you want to specify that it's a root element.

    Also in case you developing an UWP app with MasterDetailPage you should keep in mind:

    Generally, you'll set these two properties to objects of type ContentPage, but currently, to get MasterDetailPage to work on the Universal Windows Platform, the detail page must be a NavigationPage.