如何将字符串参数传递给EventHandler?

ViewController(A)
书面事件处理程序

    public event EventHandler ValueChanged;

    void ResponseCompleted(object sender, CommonCode.ResponseEventArgs e){
        this.InvokeOnMainThread (delegate {

        if (ValueChanged != null) {
        ValueChanged (this, new EventArgs (e.ResponseData));
// e.ResponseData is an String datatype.
         }
     });
    }

ViewController(B)
relatedDataSource.ValueChanged += delegate {
 Get Response Data from ViewControllerA
}

最佳答案

您可以使用通用EventHandler。例如:

public event EventHandler<string> ValueChanged;

void ResponseCompleted(object sender, CommonCode.ResponseEventArgs e){
    this.InvokeOnMainThread (delegate {

    var handler = ValueChanged;
    if (handler != null)
        handler(this, e.ResponseData);
    });
}

relatedDataSource.ValueChanged += (s, responseData) => {
    //Your data is in responseData variable
}

10-06 09:01