如何解决“编译器错误 - 无法从方法组转换成System.Delegate'? [英] How do I fix 'compiler error - cannot convert from method group to System.Delegate'?

查看:1220
本文介绍了如何解决“编译器错误 - 无法从方法组转换成System.Delegate'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 public MainWindow()
 {
    CommandManager.AddExecutedHandler(this, ExecuteHandler);
 }

 void ExecuteHandler(object sender, ExecutedRoutedEventArgs e)
 {
 }

错误1参数2:无法从方法组转换为System.Delegate

Error 1 Argument 2: cannot convert from 'method group' to 'System.Delegate'

推荐答案

我想有不同的签名的多个ExecuteHandler。只投​​你的处理器的版本,你想有:

I guess there are multiple ExecuteHandler with different signatures. Just cast your handler to the version you want to have:

CommandManager.AddExecuteHandler(this, (Action<object,ExecutedRoutedEventArgs>)ExecuteHandler);

这篇关于如何解决“编译器错误 - 无法从方法组转换成System.Delegate'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆