Xamarin Visual Studio 2017: Cannot Add Cross-Platf

2020-07-22 16:43发布

问题:

So I use the Xamarin Cross-Platform application template. I want to add LoginPage.xaml view to my project. So I choose add -> new item -> contentpage.

There is always error:

The project system has encountered an error:

Did not find new element in the hierarchy for item "Views\LoginPage.xaml". The item would have been added with type "Page". The project item schema service knows about this item type. The item does exist in the project file.

After I close the error. There is another error:

Microsoft Visual Studio

Exception of type "System.Exception" was thrown.

Then what happenend next is the "LoginPage.xaml" file is created but not included in the project (it is hidden). I cannot include it in my project because it keeps refusing. There is no xaml.cs file created.

How can I fix this?

回答1:

This issue is officially "Under Investigation" (reported and answered: https://developercommunity.visualstudio.com/content/problem/160939/bug-adding-xaml-content-page-to-shared-project-xam.html) and there is a workaround:

a workaround is to install the Universal Windows Platform development workload



回答2:

The best I could do was actually add it in a different version of Visual Studio. I just happened to have both 2015 and 2017 installed. My VS 2015 didn't give me as many options for templates, so I ended up making content pages and later changing the markup to master or whatever I needed. Just FYI, I've also found that sometimes I can add an XAML page, but it separates the .xaml and .xaml.cs instead of nesting them.