0

Do Microsoft actually provide a build of Rx / Silverlight Toolkit DragDrop that "just works" on WPF?

From what I can tell the Rx DragDrop stuff is only available in the SL Toolkit (not WPF).

The SL Toolkit seems to imply you can use it in WPF (various #defines) but gives no further info on how to do it.

If I just want the DragDrop stuff is it easy to port it to WPF, or does 100M lines of SL Toolkit come along for the ride?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113
  • I never liked the SL toolkit implementation, not very MVVM, its unlikely u want to drag element around from one to the next. more likely you want to association a payload of data, spin up a specific template for the drag operation and drop the payload on a drop target of some kind. Just my 2 cents! – Keith Jun 08 '10 at 20:54
  • There is an awesome one for WPF http://code.google.com/p/gong-wpf-dragdrop/ unfortunately I have no idea for silverlight - it might be too early days - maybe you could convert gong's to work with SL but it's a long shot. – keyle Mar 03 '11 at 04:40

1 Answers1

0

I can't comment too much on the Silverlight Toolkit, but I can on Rx.

The Reactive Extensions (Rx) are a general purpose set of libraries to enable "lifting" of various "push" collections (events, async operations, etc) into a first-class, LINQ-enabled, compositional framework. It is available for Silverlight, XNA & javascript, but more importantly for .NET 4.0 & .NET 3.5SP1 so it can be used with WPF. (The .NET 3.5SP1 implementation even back-ports much of the parallel task library which can be extremely useful even if you don't use the core Rx code.)

That said, because Rx is general-purpose, and if you can do drag-and-drop using events in WPF, then you can use Rx.

A drag-and-drop query would look something like this:

var mouseDowns =
    Observable.FromEvent<MouseButtonEventArgs>(element, "MouseDown");

var mouseMoves =
    Observable.FromEvent<MouseEventArgs>(element, "MouseMove");

var mouseUps =
    Observable.FromEvent<MouseButtonEventArgs>(element, "MouseUp");

var mouseDragPoints =
    (from md in mouseDowns
        select (from mm in mouseMoves.TakeUntil(mouseUps)
                select mm.EventArgs.GetPosition(element))).Switch();

var mouseDragDeltas =
    mouseDragPoints.Skip(1).Zip(mouseDragPoints, (p1, p0) =>
        new Point(p1.X - p0.X, p1.Y - p0.Y));

I've quickly thrown this code together without testing it, but it should give you a observable of the Point deltas from the original drag starting point and it will do so only during a drag operation. I've tried to keep the code simple. You'd need to modify for your specific needs.

If the Silverlight Toolkit provides anything further then it will just be a relatively thin layer of helper methods that you could either re-invent or use Reflector.NET to extract out and use in your app.

I hope that helps.

Enigmativity
  • 113,464
  • 11
  • 89
  • 172