且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2021-11-16 08:52:10

我已经遇到过几次,并且一直忘记是什么原因造成的. 当我重命名文件后面的代码中的名称空间而不是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.

命名空间名称必须匹配,因为它们都是部分类的一部分

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">