Project Description

Silverlight Drag Drop Manager allows you to easily implement drag and drop behaviour in your Silverlight projects by providing a DragSource & DropTarget control, which act as a content container and can contain any SL user control. Highly configurable.

 
Silverlight Control Builder Contest 1st prize award

"Probably the most customizable, feature-rich, free way to enable Drag 'n Drop in your Silverlight applications"
(yup, I made that tagline up myself ;-))

Latest release, v2.0: 09/09/2009 (September release)

Version 2.0 has been released. This is a major release, including various bugfixes, performance enhancements and loads of new features, including the ability to customize the return & switch-animations with easing & duration, the ability to customize the DropBorderBrush, a DropMode-property defining what should happen when you drop a DragSource, an AllowAnyDropTarget-property (so you don't have to manually add a list of valid DropTargets for each DragSource), a DragHandleMode-property, and many more.

Version 2.0 comes in 2 flavours: binaries for SL2 and binaries for SL3, including an updated sample application in the SL3 version. If possible, I'd advise you to use SL3 (it allows for easing animations with the Drag and Drop manager), but if you've still got a project in SL2 that's been using a previous release of this software, you can safely upgrade.

Make sure you check it out!

Get it from the "Downloads"-tab.

For the latest news and updates (on this project and other stuff I'm doing), you can follow me on Twitter.

Latest sourcecode commit: 09/09/2009

If you want access to newly added features, optimizations, ... get the latest version via the "Source Code"-tab. More info about what's been committed but not yet released can be found in this discussion board topic.

First look / running sample

To view a running sample of the Drag And Drop Manager in action with different behaviours applied (so you can see some of the things you can do with it), click here! This example application was built using the SL3-version of the Drag and Drop Manager, release v2.0.

Releases

You can find the latest release (including sourcecode, sample application & documentation) here (current release: V2.0, September 2009).

The previous releases (V1.0 & v1.1) can still be downloaded as well.

Overview / getting started

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!

The release contains all the sourcecode, the necessary binaries, the sample application. You can also download a generated help file (made using Sandcastle & DocProject).

About the author

My name is Kevin Dockx, and I'm a project leader/technical consultant @ RealDolmen, a Belgian ICT company. Next to that, I'm a Rich App Solution Manager, which boils down to the creation, implementation and follow-up of a business plan concerning Rich Applications at my company,

I'm a Silverlight enthusiast, interested in all (new :-)) things ASP .NET / Silverlight.

For more on Silverlight and related stuff, have a look at my site!

Deeper dive into the Drag And Drop Manager

Properties exposed by DragSource:

AllDropTargetsValid:
When this is set to true, all droptargets on the page will be valid for this dragsource. The droptarget-list-property will effectively be ignored when this is set to true (default: false)

AutoFitGhost:
Determines wether or not to auto-fit the ghost control. It this is true, the ghost (if available) will be resized to match the content (default: false)

Content:
Contains the control you want to make draggable

DraggingEnabled:
Determines wether or not to dragging is enabled (default: true)

DragHandleMode:
This property determines how you can drag your dragsource around: by using a draghandle (a bar on top of your dragsource), or without one, meaning you can drag by clicking anywhere in the dragsource

DropMode:
Determines the behaviour when a dragsource is dropped, and the drop is valid: by default, the dragsource is dropped on the droptarget. If you set DropMode to "ReturnDragSource", the dragsource is returned to where it originated from. This mode can be useful if you just want to execute some code on dropping (dragsourcedropped event on droptarget is triggered and can be handled if you add a handler to it), but you do not want the dragsource to be removed from the originating collection.

DropTargets:
A list of valid droptargets for this dragsource

Ghost:
Contains the ghost control, shown on original position when dragging

GhostVisibility:
Determines wether or not to show the ghost (default: Visible)

ReturnAnimationDuration:
Determines the length of the animation shown when returning a DragSource to its original position (default: 0.2)

ReturnAnimationEasingFunction:
Determines the easing function of the animation shown when returning a DragSource to its original position (default: none, Silverlight 3 (or higher) required)

SwitchAnimationDuration:
Determines the length of the animation shown when switching 2 DragSources (default: 0.2)

SwitchAnimationEasingFunction:
Determines the easing function of the animation shown when switching 2 DragSources (default: none, Silverlight 3 (or higher) required)

ShowReturnToOriginalPositionAnimation:
Determines wether or not to show an animation when returning to the original position (default: true)

ShowSwitchReplaceAnimation:
Determines wether or not to show an animation when switching/replacing 2 dragsources (default: true)

Events exposed by DragSource:

DragFinished, DragMoved & DragStarted

Properties exposed by DropTarget:

AllowPositionSave
Determines wether or not the position of a droptarget should be saved. Setting this option to true results in a significant increase in performance: in regular mode (when this property is false), droptarget positioning is calculated on the fly while dragging a dragsource. When this is set to true, it's only calculated when the droptarget is loaded. Do keep in mind that setting this to true will result in strange behaviour if the droptarget hasn't got a fixed position on screen (eg: when the droptarget itself can be moved around). However, you can recalculate this position by hand by calling the "RecalculatePosition"-method on the droptarget!. This option is advised when you have lots and lots of droptargets on one screen - in other cases, it shouldn't be necessary.

Content:
Contains the content control for a dragtarget

DropBorderBrush:
The brush for the drop border

DropBorderCornerRadius:
The cornerradius of the drop border

DropBorderThickness:
The thickness of the drop border

Ghost:
Ghost control, shown when nothing has been dropped

GhostVisibility:
Determines wether or not the ghost control should be shown (default: Visible)

RemoveElementDropBehaviour:
If you drop an item on a droptarget which already has a dragsource, and the existing dragsource hasn't got the permission to be dropped where the item you're dropping was residing (or the item you're dropping isn't the child of a droptarget at all), what should happen? Replace the existing dragsource (and thus removing it altogether) or disallow the drop?

ShowHover:
Determines wether or not a hover effect should be visible when hovering a dragsource over this droptarget

Events exposed by DropTarget:

DragSourceDropped, DropTargetEntered & DropTargetLeft

Last edited Nov 2, 2009 at 9:50 AM by KevD, version 22