Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 and C# - Unable to add event handler

Tags:

c#

wpf

xaml

I am working on WPF project, and after I made everything in Xaml file I wanted to start doing on my CS file. Now, I was trying to add event using that little bolt in properties, but everytime i click on any event (for example I select button in XAML and try to add -> MyButton_Click) i get a pop-up message "UNABLE TO ADD EVENT HANDLER".

I hope you are able to help me.

like image 244
HC1122 Avatar asked Mar 24 '15 14:03

HC1122


2 Answers

yes, @will is right, I also suffered from the same problem,when i was new in WPF. Please check your x:Class in your XAML file, it should include the namespace used in code behind. e.g., x:Class="MainWindow" should be some thing like x:class="namespace.MainWindow" if it doesn't work,try to restart the VS or try to recreate the project with correct name, hope it will solve your problem.

like image 80
Abdullah Obaidullah Avatar answered Sep 24 '22 17:09

Abdullah Obaidullah


I suffered from the same problem like you. Error occurs when you have any syntax error in your XAML file like misspell, missing tag, comma, lack of method/event handler or difficulties with references.

Exactly the same reason is when you are unable to add event or change any property in Property Window, but without any message or error. Check your syntax carefully.

Regards.

like image 27
Bear Avatar answered Sep 24 '22 17:09

Bear