New to Telerik UI for WPF? Download free 30-day trial

Customizing Drag Drop Behavior

The drag and drop functionality of the file browser is implemented via a DragDropBehavior. The default behavior is a class of type FileBrowserDragDropBehavior and can be accessed or replaced through the DragDropBehavior property of the dialog control.

To customize the behavior, you can create a new class that derives from FileBrowserDragDropBehavior and override its virtual methods.

The following example will show you how to create a behavior that allows you to drag files only, but not folders. To do so you will need to override the CanDragStart method of the behavior and based on the information received from the DragDropState class return true or false.

Example 1: Custom drag drop behavior

public class CustomFileBrowserDragDropBehavior : FileBrowserDragDropBehavior 
    public override bool CanStartDrag(DragDropState state) 
        // Here we implement the custom logic that checks if the dragged item is a file or a folder. 
        string draggedFilePath = state.DraggedFiles.FirstOrDefault(); 
        FileAttributes fileAttributes = File.GetAttributes(draggedFilePath); 
        if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory) 
            return false; 
            return base.CanStartDrag(state); 

Example 2: Setting the custom behavior

RadOpenFileDialog openFileDialog = new RadOpenFileDialog(); 
openFileDialog.Owner = theOwnerWindow; 
openFileDialog.DragDropBehavior = new CustomFileBrowserDragDropBehavior();   

This example was designed for the scenario where you can drag/drop only a single item. For multiple selection you will need to extend the example.

See Also

In this article