Phani
Phani

Reputation: 181

Adding MasterDetails Page in Xamarin forms giving (the namespace already contains definition for xx)

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.

Upvotes: 0

Views: 349

Answers (1)

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

Upvotes: 2

Related Questions