在xaml.cs文件上的InitializeComponent()上获取错误 [英] getting an error on InitializeComponent() on xaml.cs files

查看:233
本文介绍了在xaml.cs文件上的InitializeComponent()上获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我会收到红色错误消息:

I will sometimes get a red error that says:

InitializeComponent在当前上下文中不存在

InitializeComponent does not exist in the current context

与我在.xaml中具有的其他受x:Name约束的变量一起. Xaml文件中的x:Class确实与我的xaml.cs文件中的名称空间和类名称相对应.

Along with the other variables that I have in my .xaml that are bound by x:Name. The x:Class in the Xaml file does correspond to the namespace and class name in my xaml.cs file.

我的xaml文件的构建操作设置为嵌入式资源",而我的xaml.cs文件的构建操作设置为编译".该错误仅随机出现,即使出现红色错误,该项目也能正常运行.我正在使用Xamarin的Visual Studio在Windows 8.1上进行开发.

The build action for my xaml file is set to "Embedded Resource" and the build action for my xaml.cs file is set to "Compile". The error only appears randomly and the project runs like normal even with the red errors. I am developing on windows 8.1 with Visual Studio with Xamarin.

即使代码运行了,我也不想看到那些错误出现.有什么原因会发生这种情况吗?

Even though the code runs, I would like to not see those errors appear. Is there any reason why this is happening?

推荐答案

如果您使用的是共享项目,则无法使这些错误"消失. SAP无法识别InitializeComponent()方法,因此将其标记为错误,因为后面的代码在您运行它之前无法识别x:Name.

If you're using shared project you can't make those "errors" disappear. SAP does not recognize the InitializeComponent() method, so it marks it as an error, because of that the code behind does not recognize the x:Name till you run it.

编辑2015年8月11日

PCL不应给您这种错误,请检查您的xaml命名空间x:Class和xaml.cs(后面的代码)命名空间是否相同.

PCL shouldn't be giving you this kinds of errors, check that your xaml namespace x:Class and your xaml.cs (code behind) namespace is the same.

您可以做的另一件事是将Xamarin.Forms引用更新为最新版本(包括预发行版).

Another thing you can do is to update your Xamarin.Forms reference to the latest (pre-release included).

这篇关于在xaml.cs文件上的InitializeComponent()上获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆