Type objectType = Application.Current.MainWindow.GetType();
EventInfo CtrlEventInfo = objectType.GetEvent(strEventName);
if (CtrlEventInfo == null)
{
return;
}
Type TypeDelegate = CtrlEventInfo.EventHandlerType;
MethodInfo methodInfo = typeof(MyPOS.Controls.ActiveAccounts.ViewCtrl).GetMethod(strMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
Delegate DelHandler = Delegate.CreateDelegate(TypeDelegate, this, methodInfo);
CtrlEventInfo.AddEventHandler(Application.Current.MainWindow, DelHandler);
无法绑定到目标方法,因为其签名或安全透明度与委托类型的方法不兼容
被抛出
Delegate DelHandler = Delegate.CreateDelegate(TypeDelegate, this, methodInfo);
答案 0 :(得分:2)
我认为您需要将代码更改为
MyPOS.Controls.ActiveAccounts.ViewCtrl obj= new MyPOS.Controls.ActiveAccounts.ViewCtrl();
Delegate DelHandler = Delegate.CreateDelegate(TypeDelegate, obj, methodInfo);