[英]c# does not contain a definition for "InitializeComponent" and name "controlName" does not exist in current context
I've been developing a windows phone app in a team since June.自 6 月以来,我一直在团队中开发 windows 电话应用程序。 Everything worked fine with all the syncs until today.
直到今天,所有同步都运行良好。 I synced the project and vs started giving me the errors
我同步了项目,vs 开始给我错误
I didn't change anything, it worked fine yesterday.我没有改变任何东西,昨天它运行良好。 Classes names on XAML match the names in code-behind.
XAML 上的类名称与代码隐藏中的名称匹配。
I've tried exited all vs instances but the problems are still there.我已经尝试退出所有 vs 实例,但问题仍然存在。
For me, the problem was following: 对我来说,问题在于:
Project structure 项目结构
Project\Views\Page1.xaml
Project\Views\Page1.xaml.cs
The error in Page1.xaml.cs
on abovementioned page constructor: 上述页面构造函数中的
Page1.xaml.cs
的错误:
public sealed partial class Page1 : Page
{
public Page1()
{
this.InitializeComponent();
}
}
Xaml file XAML文件
<Page
x:Class="App1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
should be x:Class="App1.Views.Page1"
应该是
x:Class="App1.Views.Page1"
so just typo in the class name. 因此,只需在班级名称中输入错字即可。
Close the solution, delete the.suo file associated with the solution, delete the "bin" and the "obj" folders in all projects.关闭解决方案,删除与解决方案关联的.suo文件,删除所有项目中的“bin”和“obj”文件夹。 Then re-open the solution in VS and rebuild the solution.
然后在VS中重新打开解决方案,重建解决方案。
The "suo" file is a hidden file so you may need to go in the explorer to menu / View and there check the "Hidden items" option. “suo”文件是一个隐藏文件,因此您可能需要在资源管理器中按 go 到菜单/查看,然后勾选“隐藏项目”选项。 In VS2013 it was in the same folder as the.sln file, in newer versions it's in the (hidden).vs folder.
在 VS2013 中,它与 .sln 文件位于同一文件夹中,在较新的版本中,它位于(隐藏).vs 文件夹中。
For me, the problem was app was running in background.对我来说,问题是应用程序在后台运行。
There was no app window or icon in the taskbar.任务栏中没有应用程序 window 或图标。 The application instance persisted even when Visual Studio was closed , preventing me from manually clearing
/bin
and /obj
in Solution because Windows threw 'files currently in use' exception.即使 Visual Studio 关闭,应用程序实例仍然存在,阻止我手动清除 Solution 中的
/bin
和/obj
,因为 Windows 抛出了“当前正在使用的文件”异常。
Solution is to解决办法是
CTRL
+ SHIFT
+ ESC
)CTRL
+ SHIFT
+ ESC
) 终止应用程序Restarting the system will also work.重新启动系统也将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.