Xamarin - The Master and Detail must be set before adding the MasterDetailPage to the container

I am trying to add a simple Master Detail page to an existing Xamarin application. Here is the announcement of MasterDetailPage

<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 launch the application, I get the following error when navigating the page:

The master and part must be installed before adding the MasterDetailPage to the Container

I assume this is due to autofac, which is used as an IOC container in the application, but havent been able to drag a finger on it. Has anyone else experienced this?

+5
source share
4 answers

Try looking at this link, it solved my problem, https://github.com/rid00z/FreshMvvm/issues/64 .

+3
source

Here is my startup code if someone needs 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> 
+2
source

I forgot to use InitializeComponent(); for my MasterDetailPage code behind the file. In your case, it should be SettingsPage . I commented on this because once he showed me a mistake.

0
source

You can try: Open a simple class for the details homepage. Set the name to MyMasterPage (specify the name you want).

 public class MyMasterPage : MasterDetailPage { public MyMasterPage() { this.Master = new MenuPage();//name of your menupage this.Detail = new DetailPage();//name of your detailpage } } 

You now have a wizard page. The last thing you should add 2 ContentPage is one for the menu page, the other for DetailPage.

0
source

All Articles