如果我在Visual Studio 2010 SP1中创建一个新项目,并选择“WPF应用程序”,并尝试构建生成的应用程序,我会得到错误

名称“InitializeComponent”在当前上下文中不存在。

今天早上,当我试图构建当前项目时,我遇到了类似的错误。昨天,我编译和运行它没有问题。

我创建了一个新项目,每当我编译项目时,都会得到错误。我刚刚把项目发给了同事,他刚刚编译完成,没有任何错误。

怎么了?


当前回答

是的,很多事情都可以…我要加上这一条…… 确保app .xaml指向你的命名空间(app文件所在的位置)+ .App 如。 x: Class = " DX。App" <===确保这是App而不是主页名

希望这也适用于你。

其他回答

是的,很多事情都可以…我要加上这一条…… 确保app .xaml指向你的命名空间(app文件所在的位置)+ .App 如。 x: Class = " DX。App" <===确保这是App而不是主页名

希望这也适用于你。

我尝试了上面所有的建议。如果你太努力而没有成功,那就走更容易的路。创建一个新页面。xaml然后复制新类的代码并删除有问题的类xaml。不要花更多的时间。

导航到解决方案目录 删除\obj文件夹 重新构建解决方案

我在重构过程中遇到了这个错误,我重命名了一些文件/文件夹,并且需要重新生成预先存在的*.g.cs文件。

右键单击项目中的文件夹以创建新的UserControl,这是我的问题。 我在文件夹外创建了相同的控件,就是这样。

I had a problem similar to this in WPF. I had copied a usercontrol but had forgotten to rename the public ViewModel property in its.xaml.cs file for it. But still wasn't working. I eventually deleted all of the files inside the obj\debug type of folder for the project (we had this named differently). And rebuilt it. It still wasn't working, and I exited Visual Studio. (Before this I had at one point two instances of Visual Studio I think maybe.) The problem I had was that it was reporting it had this error when I had already fixed it! When I came back into Visual Studio (after deleting the debug stuff in obj), there finally was no error indicator. Then I rebuilt the project and now all was good!

这和我之前做的顺序不一样。它需要被简化。