TechDays 2011: Rx talk, slides and source code
Rx, Silverlight, Windows Phone, WPF February 13th, 2011As promised, here is a blog post which shares source code and slides for the Rx talk I gave during last TechDays in Paris. I animated this session with my co-worker Charlotte and with Mitsu.
Download slides here.
Download source code here.
Demo1: Drag’n'drop in a WPF application
The goal was to implement a basic drag’n'drop functionality in a WPF application. The Rx query looks like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var query = from mouseDown in this.image.GetMouseLeftButtonDownObservable() let downPosition = mouseDown.EventArgs.GetPosition(this) let rect = new Rect(downPosition.X - 10, downPosition.Y - 10, 20, 20) let delta = mouseDown.EventArgs.GetPosition(this.image) from mouseMove in this.GetMouseMoveObservable() .Select(ea => ea.EventArgs.GetPosition(this)) .SkipWhile(p => rect.Contains(p)) .DoOnce(p => this.onMouseEnter.Begin(this.image)) .Select(p => p.Offset(delta)) .TakeUntil(this.GetMouseLeftButtonUpObservable()) .Finally(() => this.onMouseLeave.Begin(this.image)) select mouseMove; query.Subscribe(p => this.image.SetPosition(p)); |
Demo2: online Twitter search and Bing map geolocalization
This time, the goal was to query Twitter asynchronously and to geolocalize the associated Tweets. The Rx query:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | this.textbox.GetTextChangedObservable() .DistinctUntilChanged((ea) => this.textbox.Text) .Throttle(TimeSpan.FromMilliseconds(300)) .ObserveOnDispatcher() .Do(ea => this.ShowLoadingIndicator()) .Select(ea => TweeterHelper.Search(this.textbox.Text)) .Switch() .ObserveOn(Scheduler.Dispatcher) .Select(page => TweeterHelper.ParseTwitterSearch(page)) .Subscribe((tweets) => { this.HideLoadingIndicator(); this.listbox.ItemsSource = tweets; TweeterHelper.LocalizeTweets(this.map, tweets); }); |
Demo3: using the accelerometer in a Windows Phone 7 application
The last demo was about the usage of the accelerometer in a Windows Phone 7 application. Here is the relevant Rx query:
1 2 3 4 5 6 7 8 9 10 | private void MoveEllipse(IObservable<Acceleration> accelerationObservable) { accelerationObservable .SlidingBuffer(2) .Select(accCouple => new Acceleration(accCouple.First(), accCouple.Last())) .ObserveOnDispatcher() .Do(acc => this.textBlock.Text = acc.ToString()) .Scan(new Point(x0, y0), (point, acc) => point.Move(acc).ClipTo(horizontalInterval, verticaInterval)) .Subscribe(p => this.ellipse.SetCenter(p)); } |
Doing this session was a really great experience ! I’d like to thank Charlotte and Mitsu for doing it with me. Also, I’d like to thank all users who came to the presentation !



March 27th, 2011 at 11:12 am
I love every single post in your blog! Minor point: in some code snippets lambdas are being shown with “=>” instead of “=>”
March 27th, 2011 at 11:13 am
… I mean “= & g t ;”
March 28th, 2011 at 9:25 am
Thanks for the feedback Mikhail. I just fixed that.