0
votes

I have created a new Xamarin forms project with PCL option and added a masterdetailpage with name MainPage. Once added I am getting error saying MainPage already exists. I am using VS2017 and latest version of Xamarin.

Error   CS0101  The namespace '' already contains a definition for 'MainPage'   \obj\Debug\xxxxxxMainPage.xaml.g.cs

Any help much appreciated. Thanks.

Edit:

https://forums.xamarin.com/discussion/89346/forms-master-detail-page-generation-is-broken

This has got the answer.

1
Strange, either something is going wrong in VS2017, or you have created two objects called MainPage in your projectGerald Versluis
I am not sure there is no class with same name. Its generated a class with .g.cs for the xaml which has got partial class declaration as well.Phani

1 Answers

2
votes

There's some bugs creating a MasterDetailPage

Let's asume that i've created a project named MyApp and a MasterDetailPage named Page1

1) It would appear, that the added pages have the wrong namespace. So change the namespace on the added pages

Visual Studio add to the new pages namespace MyApp.Page1

    Page1.xaml.cs - change the Namespace to be just MyApp
   Page1Detail.xaml.cs - Change the namespace to be just MyApp
   Page1Master.xaml.cs - Change the namespace to be just MyApp
   Page1MenuItem.cs - Change the namespace to "MyApp"

2) I also noticed that in the Page1Master.xaml.cs it is incorrectly referencing the MenuItems.

    It says Page1MenuItems = new ObservableCollection...
Change that to be just
MenuItems = new ObservableCollection...

That works 4 me

Hope it helps