title: Master and Detail must be set before adding MasterDetailPage to a container error in Xamarin forms
body: <p>I have a xamarin forms application. The layout is created by using custom rootpage.cs file. it has the navigation menu for navigating the pages. In the App.cs file redirect to root page by </p>
  
  <p><code>MainPage = new RootPage();</code></p>
  
  <p>Inside the rootPage class file</p>
  
  <pre><code>Dictionary&lt;MenuType, NavigationPage&gt; Pages { get; set; }
      public RootPage()
      {
          Pages = new Dictionary&lt;MenuType, NavigationPage&gt;();
          Master = new MenuPage(this);
          BindingContext = new BaseViewModel
          {
              Title = "Manager",
              Icon = "icon.png"
          };
          NavigateAsync(MenuType.Home);
          InvalidateMeasure();
      }
      public async Task NavigateAsync(MenuType id)
      {
          Page newPage;
          if (!Pages.ContainsKey(id))
          {
              switch (id)
              {
                  case MenuType.Home:
                      Pages.Add(id, new NavigationPage(new HomePage()));
                      break;
                  case MenuType.AboutUs:
                      Pages.Add(id, new NavigationPage(new ContactUsPage()));
                      break;
              }
          }
          newPage = Pages[id];
          if (newPage == null)
              return;
          Detail = newPage;
          IsPresented = false;
      }
  </code></pre>
  
  <p>In the  menu page class file have the below code</p>
  
  <pre><code>RootPage root;
      public MenuPage(RootPage _root)
      {
          root = _root;
          InitializeComponent();
          List&lt;HomeMenuItemModel&gt; menuItems;
          BindingContext = new BaseViewModel
          {
              Title = "Sample App",
              Subtitle = "Sample App",
              Icon = "icon.png"
          };
          ListViewMenu.ItemsSource = menuItems = new List&lt;HomeMenuItemModel&gt;
              {
                new HomeMenuItemModel { Title = "Home", MenuType = MenuType.Home, Icon ="icon.png" },
                new HomeMenuItemModel { Title = "Contact Us", MenuType = MenuType.ContactUs, Icon ="icon.png" },
                new HomeMenuItemModel { Title = "About Us", MenuType = MenuType.AboutUs, Icon ="icon.png" },
              };
          ListViewMenu.SelectedItem = menuItems[0];
          ListViewMenu.ItemSelected += async (sender, e) =&gt;
          {
              if (ListViewMenu.SelectedItem == null)
                  return;
              if (e.SelectedItem != null)
                  await this.root.NavigateAsync(((HomeMenuItemModel)e.SelectedItem).MenuType);
              ListViewMenu.SelectedItem = null;
          };
      }
  </code></pre>
  
  <p>HomePage.xaml is just a content page.
  While the first run of the application it shows an error "Master and Detail must be set before adding MasterDetailPage to a container error" 
  I am new to xamarin. Could you please suggest a solution for this.</p>