I am trying to play with the reactive extension hands on lab but could not register using the FromEvent API (I am getting compile time exception). I want to receive events when the textchanged property is invoked on the text box control, can someone suggest what am i doing wrong on the conversion via FromEvent API? I some how cannot type cast or convert from TextChangeEventArgs/EventHandler to EventHandler - please show me the right way to do it. Thanks.
internal delegate void TextChangedEventArgs(object sender, EventArgs e);
var txt = new TextBox();
var form = new Form
{
Controls = { txt }
};
var subscription = Observable.FromEvent<EventHandler, TextChangedEventArgs>(
x => (a, b) => new EventHandler(), ??????
x => txt.TextChanged += x,
x => txt.TextChanged -= x
);
IDisposable eventSubscription = subscription.Subscribe(
x => Console.WriteLine("Subscriber Got " + x),
x => Console.WriteLine("An exception has occured" + x),
() => Console.WriteLine("Action completed"));
Console.WriteLine("in here");
using (new CompositeDisposable(eventSubscription)) { Application.Run(form); }
Console.ReadKey();
Try this:
var subscription = Observable.FromEventPattern<TextChangedEventArgs>(txt, "TextChanged");
Try:
var subscription = Observable.FromEvent(h => txt.TextChanged += h,
h => txt.TextChanged -= h);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With