I am trying to add a simple Master Detail page to an already existing Xamarin application. Here is the MasterDetailPage declaration
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                  xmlns:pages="clr-namespace:MyCareManager.XamForms.Pages;assembly=MyCareManager.XamForms"
                  x:Class="MyCareManager.XamForms.Pages.SettingsPage">
  <MasterDetailPage.Master>
    <ContentPage Title="This is the test master page"></ContentPage>
  </MasterDetailPage.Master>
  <MasterDetailPage.Detail>
    <NavigationPage>
      <x:Arguments>
        <ContentPage Title="This is a view"></ContentPage>
      </x:Arguments>
    </NavigationPage>
  </MasterDetailPage.Detail>
</MasterDetailPage>
However, when I run the application I get the following error when navigation through to the page :
Master and Detail must be set before adding MasterDetailPage to a container
I am assuming that it is to do with autofac that is being used in the application as an IOC container but havent been able to put a finger to it. Has anyone else experienced this?
Here is my running code if some one need it :
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="CrossApp1.MenuPage">
        <MasterDetailPage.Master>
          <ContentPage Title="Menu">
            <StackLayout Orientation="Vertical">
              <Button Text="Sports"/>
              <Button Text="Economy"/>
              <Button Text="Education"/>
              <Button Text="Science"/>
            </StackLayout>
          </ContentPage>
        </MasterDetailPage.Master>
        <MasterDetailPage.Detail>
          <NavigationPage>
            <x:Arguments>
              <ContentPage Title="This is a view"></ContentPage>
            </x:Arguments>
          </NavigationPage>
        </MasterDetailPage.Detail>
</MasterDetailPage>
I solved this issue by adding Detail section of MasterDetailPage
Like this
<MasterDetailPage.Master>
    <ContentPage Title="Menu">
        <StackLayout Padding="20">
            <Button Text="ViewA"/>
        </StackLayout>
    </ContentPage>
</MasterDetailPage.Master>
<!--Add below code too-->
<MasterDetailPage.Detail>
    <NavigationPage>
        <x:Arguments>
            <ContentPage Title="This is a view"></ContentPage>
        </x:Arguments>
    </NavigationPage>
 </MasterDetailPage.Detail>
I forgot to use InitializeComponent(); on my MasterDetailPage code behind file. In your case that must be SettingsPage. I had commented it out, because he showed me an error one time.
You can try this: Open a simple class for Master Detail Page. Set the name MyMasterPage (set the name what you desire).
public class MyMasterPage : MasterDetailPage
    {
        public MyMasterPage()
        {
            this.Master = new MenuPage();//name of your menupage                
            this.Detail = new DetailPage();//name of your detailpage
        }
    }
Now you have your Master Detail Page. Last thing you should add 2 ContentPage one is for Menu Page, other for DetailPage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With