101 Rx Examples


Answer :

I actually had similar thoughts a couple days ago. We started our own "101 Rx Samples" as a post in the Rx MSDN forum, but we have since moved it to a Wiki format. Please feel free to come over and add your own samples!

101 Rx Samples on the Rx wiki


To start with - Here is a simple drawing application, so that when the user drags, we draw a red line from the initial mouse down position to the current location, and also a blue spot at the current location. This is the result of my last week's hack on Rx

A WPF Drawing Demo

And here is the source code.

//A draw on drag method to perform the draw void DrawOnDrag(Canvas e)         {              //Get the initial position and dragged points using LINQ to Events             var mouseDragPoints = from md in e.GetMouseDown()                                   let startpos=md.EventArgs.GetPosition(e)                                   from mm in e.GetMouseMove().Until(e.GetMouseUp())                                   select new                                   {                                       StartPos = startpos,                                       CurrentPos = mm.EventArgs.GetPosition(e),                                   };               //Subscribe and draw a line from start position to current position             mouseDragPoints.Subscribe                 (item =>                 {                     e.Children.Add(new Line()                     {                         Stroke = Brushes.Red,                         X1 = item.StartPos.X,                         X2 = item.CurrentPos.X,                         Y1 = item.StartPos.Y,                         Y2 = item.CurrentPos.Y                     });                      var ellipse = new Ellipse()                     {                         Stroke = Brushes.Blue,                         StrokeThickness = 10,                         Fill = Brushes.Blue                     };                     Canvas.SetLeft(ellipse, item.CurrentPos.X);                     Canvas.SetTop(ellipse, item.CurrentPos.Y);                     e.Children.Add(ellipse);                 }                 );         } 

Read my post with further explanation here and Download the source code here

Hope this helps


Another useful resource may be the Reactive Extensions (Rx) Koans: 55 progressive examples to help you learn Rx


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?