Since Q3 2010 we have introduced new drag mode, enabling native drag from and to your WPF applications. In this post I will show how to successfully perform drag drop operations from external program into your application through the RadDragAndDropManager API.

This can be achieved in several easy steps:

 

1. Set RadDragAndDropManager.EnableNativeDrag=”true”. This will enable native operations (if your application runs in full trust). The easiest way to do this is set it in StartUp event.

 

        private void Application_Startup(object sender, StartupEventArgs e)
       
{
           
RadDragAndDropManager.EnableNativeDrag = true;
       
}
 
2. Set the RadDragAndDropManager properties to enable the drop operation:
 
telerik:RadDragAndDropManager.AllowDrop="True"
telerik:RadDragAndDropManager.DropQuery="FileListGrid_DropQuery"
telerik:RadDragAndDropManager.DropInfo="FileListGrid_DropInfo"

 

and add the corresponding code within DropQuery and DropInfo

 

  private void FileListGrid_DropQuery(object sender, DragDropQueryEventArgs e)
       
{
           
if (!RadDragAndDropManager.IsDragging && e.Options.DropDataObject.ContainsFileDropList())
           
{
               
e.QueryResult = true;
           
}
       
}

       
private void FileListGrid_DropInfo(object sender, DragDropEventArgs e)
       
{
           
if (e.Options.Status == DragStatus.DropComplete && !RadDragAndDropManager.IsDragging && e.Options.DropDataObject.ContainsFileDropList())
           
{
               
var items = ((RadGridView)e.Options.Destination).ItemsSource as IList;
               
var droppedFiles = e.Options.DropDataObject.GetFileDropList();

               
if (items != null && droppedFiles != null)
               
{
                   
foreach (var droppedFile in droppedFiles)
                   
{
                       
items.Add(droppedFile);
                   
}
               
}
           
}
       
}

 

In the attached sample I have added RadGridView as well as RadTreeListView, that accepts files from the file system.

Download sample


About the Author

Tsvyatko Konov

is software developer in Telerik Windows 8 product team. You can follow him on Twitter @tsvyatco and his personal blog at www.konov.me

Comments

Comments are disabled in preview mode.