在Xamarin表单中添加MasterDetails页面(命名空间已包含xx的定义)

时间:2017-03-24 15:53:00

标签: xamarin.forms

我使用PCL选项创建了一个新的Xamarin表单项目,并添加了一个名为MainPage的masterdetailpage。一旦添加,我收到错误说MainPage已经存在。 我正在使用VS2017和最新版本的Xamarin。

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

任何帮助非常感谢。 感谢。

修改

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

这已经得到了答案。

1 个答案:

答案 0 :(得分:2)

有一些错误创建了MasterDetailPage

让我们假设我创建了一个名为MyApp的项目和一个名为Page1的MasterDetailPage

1)看起来,添加的页面具有错误的命名空间。因此,在添加的页面上更改名称空间

Visual Studio添加到新页面命名空间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)我还注意到在Page1Master.xaml.cs中它错误地引用了MenuItems。

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

这对我有用{/ p>

希望有所帮助

相关问题