C sharp: WPF: The name ‘InitializeComponent’ does not exist in the current context

Symptoms

When I compile my C# Windows Presentation Foundation (WPF) window application I receive the following error:

‘The name ‘InitializeComponent’ does not exist in the current context’

Cause

There is a mismatch between the XAML <Window x:Class=”…”> statement and the codebehind ‘namespace’ and ‘class’ definition.

Solution

Ensure XAML and codebehind are correct:

XAML

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

Codebehind

namespace ZZZ
{
   /// <summary>
   /// Interaction logic for MainWindow.xaml
   /// </summary>
   public partial class MainWindow
   {
      public void Window() : Window
      {
         InitializeComponent();
      }
   }
}
C sharp: WPF: The name ‘InitializeComponent’ does not exist in the current context was last modified: May 17th, 2016 by tabcom