Visual Studio 2013和c# -无法添加事件处理程序

时间:2023-01-14 21:21:14

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.

我希望你能帮助我。

2 个解决方案

#1


20  

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或者尝试用正确的名字重新创建项目,希望它能解决你的问题。

#2


2  

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.

和你一样,我也遇到过同样的问题。当XAML文件中出现任何语法错误时,比如拼写错误、丢失标记、逗号、缺少方法/事件处理程序或引用困难等,就会发生错误。

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.

的问候。

#1


20  

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或者尝试用正确的名字重新创建项目,希望它能解决你的问题。

#2


2  

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.

和你一样,我也遇到过同样的问题。当XAML文件中出现任何语法错误时,比如拼写错误、丢失标记、逗号、缺少方法/事件处理程序或引用困难等,就会发生错误。

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.

的问候。