Project Description
Mini Rx provides LINQ like queries over events for C# and F# using extension methods, somewhat like the Reactive Extensions (Rx) but in a lightweight open source package with one non-strong named assembly.

You need to install Microsoft Silverlight to view this content. Get Silverlight!
Get Microsoft Silverlight



    public MainWindow()
    {
        InitializeComponent();

        TrackMouse("Time flies like an arrow");
    }

    private void TrackMouse(string message)
    {
        var mouseMove =
            Observable.FromEvent<MouseEventArgs, MouseEventHandler>(
                (f) => new MouseEventHandler((sender, args) => f(args)),
                handler => MouseMove += handler,
                handler => MouseMove -= handler);
        var chars = message.ToCharArray();
        for (int i = 0; i < chars.Length; i++)
        {
            var c = message[i].ToString();
            var label = new Label() { Content = c };
            canvas.Children.Add(label);
            int closure = i;
            mouseMove
                .Select(e => e.GetPosition(canvas))
                .Delay(closure * 100)
                .OnDispatcher()
                .Subscribe(pos =>
                {
                    Canvas.SetLeft(label, pos.X + closure * 10);
                    Canvas.SetTop(label, pos.Y);
                });
        }
    }

Last edited Oct 31, 2011 at 6:04 PM by ptrelford, version 2