2016-05-12 32 views
1
 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); 

回答

2

我想你需要更改您的代碼

MyPOS.Controls.ActiveAccounts.ViewCtrl obj= new MyPOS.Controls.ActiveAccounts.ViewCtrl(); 
Delegate DelHandler = Delegate.CreateDelegate(TypeDelegate, obj, methodInfo); 
相關問題