[转] C# WPF Unable to add event handler
Visual Studio 2013和c# -无法添加事件处理程序
[英]Visual Studio 2013 and C# - Unable to add event handler
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".
我在WPF项目中工作,在Xaml文件中完成所有工作后,我想开始对CS文件进行处理。现在,我尝试在属性中添加事件,但是每次单击任何事件(例如,在XAML中选择按钮,并尝试添加-> MyButton_Click),我得到一个弹出消息“无法添加事件处理程序”。
I hope you are able to help me.
我希望你能帮助我。
解决方案
#1
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.
是的,@will是对的,我刚进入WPF的时候也遇到过同样的问题。请在XAML文件中检查您的x:类,它应该包括后面代码中使用的名称空间。例如,x:Class="MainWindow"应该是x:Class=" namespace "之类的东西。如果它不工作,尝试重新启动VS或者尝试用正确的名字重新创建项目,希望它能解决你的问题。