Xamarin Forms InitializeComponent does not exist

吃可爱长大的小学妹 提交于 2019-12-10 04:04:57

问题


I am learning Xamarin Forms for Visual Studio 2015 and trying to create a simple Shared project using Xaml but I keep getting InitializeComponent does not exist (as well as any reference to Xaml controls in cs classes).

It is my understanding that in the latest versions of Xamarin, Xaml works in Shared Xamarin Forms Projects (and not only in PCL projects). I've tried running the latest betas that got released less than a month ago but still no luck.

Any advice is greatly appreciated.


回答1:


Turns out I had to manually change the properties for all Xaml files like so:

Build Action: Embedded resource
Custom Tool: MSBuild:UpdateDesignTimeXaml

For some reason adding new Xaml forms files doesn't set these by default in VS2015 with latest Xamarin.




回答2:


I had the same issue. And it turned out to be that fully qualified Class Name in Xaml must match exactly the .cs file. I corrected the namespace casing and it worked!!




回答3:


This happens when your XAML markup is invalid. There is a background compilation task that parses the XAML file and generates a code file (this is normally hidden from the developer) which declares those control references. If your XAML is not valid then this task will fail silently, and your first hints are the symptoms you describe.

Comment out the contents of your XAML file using standard XML comment syntax (wrap it with <!-- and -->), then rebuild your project to clear out all of the errors. You may also need to comment out some code in your .cs files temporarily to get it to build. Once you get it building, then you can go back and start uncommenting your XAML until you find the part that was breaking it.




回答4:


Try it: Open the Package Manager Console, put the follow line: update-package -project your_pcl_project_name -reinstall



来源:https://stackoverflow.com/questions/36652603/xamarin-forms-initializecomponent-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!