I have a method in a silverlight application. I want to start calling this method when an event occurs (mouse move), and continue to call this method every 1 second until a simple boolean condition changes. Is this possible ? I can't work out how to get the rx to generate multiple 'events' from the single event
+2
A:
Here's a method that I used to do this:
var isChecked = from f in Observable.FromEvent<RoutedEventHandler, RoutedEventArgs>(
h => new RoutedEventHandler(h),
h => checkBox1.Checked += h,
h => checkBox1.Checked -= h)
where checkBox1.IsChecked == true
select new Unit();
var xs = from click in Observable.FromEvent<RoutedEventHandler, RoutedEventArgs>(
h => new RoutedEventHandler(h),
h => button1.Click += h,
h => button1.Click -= h)
from ping in Observable.Interval(TimeSpan.FromSeconds(1.0)).TakeUntil(isChecked)
select ping;
_subscription = xs.ObserveOnDispatcher().Subscribe(v => label1.Content = v.ToString());
I created a button to begin the events on click. I created a check box that will stop the events when it is checked. This may not be exactly what you want but the events fire as you asked and you should be able to make modifications to suit from here.
Enigmativity
2010-03-29 11:35:49