当前上下文中不存在名称“InitializeComponent" [英] The name 'InitializeComponent' does not exist in the current context

查看:67
本文介绍了当前上下文中不存在名称“InitializeComponent"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I create a new project in Visual Studio 2010 SP1 and select "WPF Application" and tries to build the generated application, I get the error

名称InitializeComponent"在当前上下文中不存在.

The name 'InitializeComponent' does not exist in the current context.

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

I got a similar error this morning when I tried to build my current project. Yesterday, I had no problem compiling and running it.

我创建了一个新项目,但每次编译该项目时都会出现错误.我刚刚把项目发给了同事,他刚刚编译没有任何错误.

I created a new project and got the error whenever I compiled the project. I have just sent the project to a colleague, and he has just compiled without any errors.

怎么了?

推荐答案

我遇到过几次,一直忘记是什么原因造成的.我在代码隐藏文件中重命名命名空间时遇到了这个问题,但在 XAML 中没有重命名.

I've encountered this a couple times and keep forgetting what causes it. I ran into this when I renamed the namespace on my code behind file but not in my XAML.

所以检查你是否做了同样的事情.

So check if you've done the same.

namespaceclass 名称需要匹配,因为它们都是部分类的一部分

The namespace and class names need to match since they are both part of a partial class

namespace ZZZ
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
         //...
    }
}

<!-- XAML -->
<Window x:Class="ZZZ.MainWindow">

这篇关于当前上下文中不存在名称“InitializeComponent"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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