How to pass an argument to an event handler in Xamarin IOS
How do I pass a string argument to EventHandler?
ViewController (A) Handler of recorded events
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
}
+3
kiran
source
to share
1 answer
You can use generic EventHandler. For example:
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
}
+4
Norfolc
source
to share