A few weeks ago, I started thinking about designing custom controls for Silverlight, controls I could re-use in various projects. Instead of just playing around, I figured I might as well make something I could put to use. Seeing I didn’t find a true, free drag ‘n drop control, I decided to make one myself.
That little project evolved into a drag and drop manager for Silverlight. There’s still room for improvement, but I’m quite happy with where the project is at at the moment. And because other people might be able to use a control like this, I decided to make a Codeplex project, so everyone can get this control for free, including sourcecode! :-)
For those of you who don’t want to read the rest, here’s the link to Drag and Drop Manager @ Codeplex. And of course, an online sample!
The Silverlight Drag And Drop Manager consists of 2 controls (and their corresponding event argument classes): *DragSource* & *DropTarget*. The first one makes any control draggable: just add the control (and if you wish, a ghost for that control) as the Content-property of the DragSource.
The DropTarget defines a place in your application where you can drop your DragSources. Every DragSource has a list of DropTargets on which it can be dropped, thus defining the possible DropTargets for a DragSource. On the other hand, every DropTarget has a Content-property, which can contain anything that’s a DragSource (assuming the correct rights).
Typically, you’d create a list of DropTargets & a list of DragSources on screen if you want to be able to drag those DragSources into your DropTargets. If you want to have two lists, and want to be able to drag the DragSources back to their original position, you ‘d create a list of empty DropTargets, and a list of DropTargets with DragSources as their Content.
Both controls can be added to your Silverlight-app using CodeBehind or using XAML notation. They both expose different events you can bind handlers to, if needed, eg: DragSourceDropped-event, DropTargetEntered event, et cetera.
Next to that, both controls are *highly configurable*, so lots of possible scenarios are available. Have a look at the sample application to see a few of them in action!
Full sourcecode, documentation, online sample & binary: Drag and Drop Manager.
Comments are welcome, discussions, feature requests, bug reports, … can be reported @ Codeplex.
Enjoy! 🙂