Getting error on InitializeComponent () in xaml.cs files

Sometimes I get a red error that says:

InitializeComponent does not exist in the current context

Along with the other variables that I have in my .xaml , which are connected by x:Name . x:Class in the Xaml file corresponds to the namespace and class name in my xaml.cs file.

In the build action, my xaml file is set to Embedded Resource, and the build action for my xaml.cs file xaml.cs set to Compile. The error appears only randomly, and the project works, as usual, even with red errors. I am developing Windows 8.1 with Visual Studio with Xamarin.

Despite the fact that the code works, I would not want these errors to be displayed. Is there a reason why this is happening?

+4
source share
2 answers

If you use a common project, you cannot make these β€œerrors” disappear. SAP does not recognize the InitializeComponent () method, so it marks it as an error, because of this, the code behind does not recognize x: Name until you run it.

EDIT 11/08/2015

PCL should not give you such errors, check that the xaml x: Class namespace and your xaml.cs (code behind) namespace are the same.

Another thing you can do is update the link to Xamarin.Forms to the latest (including the preview release).

+5
source

All Articles