Afnan Bashir
Afnan Bashir

Reputation: 7429

Unable to create Event Handler WPF

I am unable to create Event Handler when i double click on button or anything this messagebox appears enter image description here

how ever when i add event handler manually it works.any idea what might have i screwed up thanks

Upvotes: 3

Views: 9321

Answers (4)

Peck_conyon
Peck_conyon

Reputation: 241

If you have renamed the window make sure it has affected to the code behind file too as you can see in the xaml designer code. Compare the class name and window name all the places. I had the same issue and noticed when I renamed the window the associated code behind class name didn't automatically updated. So I did it manually and it was gone for good. Hope this helps :)

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564831

The class in question is the "MainWindow" class within you MainWindow.xaml.cs file. Make sure it's the first class in the code behind file.

I suspect you added another type to that file, and defined it at the top. It will "break" the designer, and give you this error message.

Upvotes: 12

Afnan Bashir
Afnan Bashir

Reputation: 7429

there was another class on top of main window in .CS file that is why it was doing problem.

Upvotes: 2

SLaks
SLaks

Reputation: 888107

Move the class code so that it is the first class in the file and try again.

Upvotes: 2

Related Questions