Vesselin Obreshkov
Vesselin Obreshkov

Reputation: 1107

Xamarin Forms InitializeComponent does not exist

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.

Upvotes: 8

Views: 5977

Answers (4)

Jimit.Gandhi
Jimit.Gandhi

Reputation: 381

I had the same issue. And it turned out to be that fully qualified Class Name (x:Class attribute in the main node) in the XAML file must match exactly the xaml.cs file's name. I corrected the namespace casing and it worked!!

Upvotes: 5

alandruizc
alandruizc

Reputation: 11

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

Upvotes: 1

Vesselin Obreshkov
Vesselin Obreshkov

Reputation: 1107

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.

Upvotes: 13

Keith Rome
Keith Rome

Reputation: 3238

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.

Upvotes: 3

Related Questions