Drag and Drop Files In Silverlight 4

Download Source


In Silverlight 4, the plugin itself supports Drag and Drop events. In this article we will see how can we use the DropTarget to capture files from local system.

Creating Silverlight Project

Fire up Visual Studio 2010 and create a new Silverlight Application Project. Name it as DragAndDropSample.

Let’s have a ListBox and a Border which can fulfill our requirement.

As you see in above image, the RightSide pane is the Drop Target and the LeftPane will Populate the list of items dropped.

Let’s have a class that will help us binding the files into listbox.

Now let’s change the default ItemTemplate of the ListBox.

Now Let’s have the Drop event of the Border so that we can capture the files.

Now that everything is done in XAML, let’s go to the code behind and write code into the DropHere event.

Now we are good to go. Let’s have some files from the local file system and drop onto the Drop Area.

That’s it.

Hope this article helps.