Silverlight Toolkit unleashes new way of Drag and Drop between controls

November 12, 2009 | by Maciej Greń

View Comments

The October release of the Silverlight Toolkit introduces several nice controls, libraries and improvements. Some time ago I described how easy it is to implement drag & drop with Silverlight 3.0. When I noticed Tim Heuers post about the new features of drag & drop I thought “what more we can get?”…we can! Imagine that you have a list box with elements that you want to reorder simply by drag & drop. Before, this required some code behind but not anymore. Have a look!

Reordering elements in list box by using drag & drop is so easy

Yes, you just have to do four things to make it work:

  • Install Silverlight Toolkit
  • Reference your project to System.Windows.Toolkit
  • Include two new name spaces in your XAML file where you have your list box (or another control that is supported, the list is below)
    xmlns:toolkit=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit”
    xmlns:mswindows=”clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit”
  • Wrap your list box, tree view, data grid into the DragDropTarget object and be happy with the new features!

It seems like the Drag and Drop feature for the TreeView control was most needed by the community. It is pretty easy to use. Generally, now we can drag and drop from lists, trees, grids and even charts! Imagine, you present a chart and you can directly drag the specific data point series to your sample grid. Awesome! More information you can find in the example links below.

Examples using Silverlight Toolkit Drag & Drop

Well in general I have found two pretty neat blog posts. One written by Tim Heuers and the second by Jafar Husain. Of course on the web you can find plenty stuff about it, but I strongly recommend to check Jafar Husain´s post because it has several nice examples.

These controls are currently supported:

  • ListBoxDragDropTarget
  • TreeViewDragDropTarget
  • DataGridDragDropTarget
  • DataPointSeriesDragDropTarget

I just have one major question. I am curious whether there is an easy way to use the same approach to extend our own customized controls. It would be nice to have some kind of interface available to make it more robust and easier to implement drag & drop into your own controls. I already left this question on Jafar Husain’s blog.

I am curious about your experiences. Feel invited to discuss Silverlight by commenting this post below!

blog comments powered by Disqus