BlankPage constructor cannot initialize components

r9s picture r9s · Apr 22, 2012 · Viewed 11k times · Source

I'm starting learning XAML and I add some code to my BlankPage application. And suddenly a constructor which is initializing a component:

    public BlankPage()
    {
        this.InitializeComponent();
    }

Stop working. I've got now that error:

'BlankApplication.BlankPage' does not contain a definition for 'InitializeComponent' and no extension method 'InitializeComponent' accepting a first argument of type 'BlankApplication.BlankPage' could be found (are you missing a using directive or an assembly reference?)

Honestly I didn't do anything, I didn't even look at this part of code and now it doesn't work.

Screenshot:

Answer

Briggs picture Briggs · Jan 3, 2013

Just to give a bit more information on how to fix this (since this explanation is a bit on the vague side)..

This issue (for me) was caused because I changed the namespace in the code after I created the project. In order to fix this issue I had to make some changes in a couple of locations:

1: In App.xaml I had to change the following:

<Application
  x:Class="New.Namespace.App"

2: In MainPage.xaml I had to change the following:

<Page
  x:Class="New.Namespace.MainPage"

You will also want to make sure that you change the 'namespace' line in your App.xaml.cs as well as your MainPage.xaml.cs.

Finally, you will also want to make sure you update the Project Entrypoint in the Package.appxmanifest to point to "New.Namespace.App".