如何在Xamarin IOS中传递参数到事件处理程序
本文关键字:参数 事件处理 程序 Xamarin IOS | 更新日期: 2023-09-27 18:18:21
如何将字符串参数传递给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
}