wpf Visual Studio 2013 和 C# - 无法添加事件处理程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29235867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio 2013 and C# - Unable to add event handler
提问by HC1122
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.
我希望你能帮助我。
回答by Abdullah Obaidullah
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:Class,它应该包含后面代码中使用的命名空间。例如,x:Class="MainWindow" 应该是类似 x:class="namespace.MainWindow" 的东西,如果它不起作用,请尝试重新启动 VS 或尝试使用正确的名称重新创建项目,希望它能解决您的问题问题。
回答by Bear
I suffered from the same problem like you. Error occurs when you have anysyntax 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.
问候。
回答by lulitha
yes. I also face this problem, I fixed it. the problem is on x:Class="MainWindow". just like @Abdullah Said.
是的。我也遇到这个问题,我解决了。问题出在 x:Class="MainWindow" 上。就像@Abdullah Said 一样。

