开发者

Use .net reactive in silverlight to generate multiple events

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 simpl开发者_如何学JAVAe boolean condition changes. Is this possible ? I can't work out how to get the rx to generate multiple 'events' from the single event


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜