English 中文(简体)
Silverlight Toolkit DragDrop on WPF
原标题:

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?

问题回答

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.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签