Xamarin.Forms - InitializeComponent doesn't exist when creating a new page

前端 未结 30 2275
不知归路
不知归路 2021-01-30 12:36

I\'m using Visual Studio to try out Xamarin.Forms. I\'m trying to follow the guide: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/xaml-for-xamarin-forms/getti

相关标签:
30条回答
  • 2021-01-30 12:57

    I have been having the same issue now and then, and this is what I have been doing to fix it: When in the PCL project, I add a new cross-platform XAML page to the project. Adding a new XAML page takes a few seconds for the references to "hook". After the new XAML page is successfully added to the project, the red underlines on the XAML Pages (with issues) will get cleared. Once the problem is solved, I simply delete the XAML file that I have just added. - So, in summary, adding a new XAML page then deleting it has been solving the issue for me.

    0 讨论(0)
  • 2021-01-30 13:00

    If you get intellisense errors such InitializeComponent in your Xamarin.Forms pages but the project actually builds and runs fine, just add a new Forms page using the wizard to fix all errors...

    Then you can delete that new page.

    0 讨论(0)
  • 2021-01-30 13:00

    This problem appears when the projects of solution are referencing the version 1.4.0.0 of the dlls "Xamarin.Forms.Core", "Xamarin.Forms.Xaml" and "Xamarin.Forms.Platform" version 1.0.0.0.

    To solve it I've had to downgrade to version 1.3.3.0 of the dlls but with this version Xamarin.Forms.Platform 1.0.0.0 don't exists.

    0 讨论(0)
  • 2021-01-30 13:00

    I don't know if this is solved, but for me, the only thing I had to do is remove the first line of the XAML ("xml version="1.0" encoding="utf-8")

    Sometimes source version control, tries to identify which type of file is and add this kind of stuff.

    0 讨论(0)
  • 2021-01-30 13:01

    As far as my observation is concerned, in Visual Studio 2015, XAML properties are already set as suggested by highly-voted answers here by default, specifically :

    • Custom Tool = MSBuild:UpdateDesignTimeXaml
    • Build Action = Embedded Resource

    but the error still appears sometimes... (like in this other question).

    Editing the corresponding XAML file and then hit CTRL+S should work fine, but you don't have to. A cleaner way to force Custom Tools to be run is by right-clicking on the XAML file and then click on "Run Custom Tool" context menu.

    0 讨论(0)
  • 2021-01-30 13:01

    It looks like the (re)generation of the blah.xaml.g.cs files is actually the problem. I get this a LOT in shared projects (which is why I don't use them unless I have no other choice). It happens way more in Xamarin Studio than Visual Studio, for me, for some reason. I try not to use XS at all.

    Often unloading one of the other platforms (e.g. if you're building droid, unload ios) and doing a clean and rebuild will fix it.

    You can also try doing something like opening one of the offending .xaml files and changing some of the xaml markup (e.g. adding or changing an x:Name to one of the controls or views). This will force a regeneration of the xaml.g.cs file, and (for me at least) usually solves the problem.

    This really shouldn't be a thing tho.

    0 讨论(0)
提交回复
热议问题