DragDropManager Migration

The article explains the events of the DragDropManager.

Events and API migration

The event that was fired when the drag Starts was DragQuery for the RadDragAndDropManager. Now it is OnDragInitialize.

Bellow is the code for the DragQuery event is its corresponding code for the OnDragInitialize event:

private void OnDragQuery( object sender, DragDropQueryEventArgs e ) 
{ 
    ListBoxItem listBoxItem = e.Options.Source as ListBoxItem; 
    ListBox box = ItemsControl.ItemsControlFromItemContainer( listBoxItem ) as ListBox; 
    if ( e.Options.Status == DragStatus.DragQuery && box != null ) 
    { 
        e.Options.Payload = box.SelectedItem; 
        ContentControl cue = new ContentControl(); 
        cue.ContentTemplate = this.Resources["ApplicationDragTemplate"] as DataTemplate; 
        cue.Content = box.SelectedItem; 
        e.Options.DragCue = cue; 
        e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue(); 
    } 
    e.QueryResult = true; 
} 

private void OnDragInitialize(object sender, DragInitializeEventArgs args) 
{ 
    args.AllowedEffects = DragDropEffects.All; // Coresponds to the QueryResult 
 
    // Coresponds to the payload setting 
    var payload = DragDropPayloadManager.GeneratePayload(null); 
    payload.SetData("DragData", ((FrameworkElement)args.OriginalSource).DataContext); 
    args.Data = payload; 
 
    // Coresponds to the cue setting (e.Options.DragCue) 
    args.DragVisual = new ContentControl { Content = args.Data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate }; 
}    

The event corresponding to the DragInfo event in RadDragAndDropManager is now DragDropComplete. The DragDropComplete event is the equivalent of the DragQuery with status DropComplete.

private void OnDragInfo( object sender, DragDropEventArgs e ) 
{ 
    ListBoxItem listBoxItem = e.Options.Source as ListBoxItem; 
    ListBox box = ItemsControl.ItemsControlFromItemContainer( listBoxItem ) as ListBox; 
    IList<ApplicationInfo> itemsSource = box.ItemsSource as IList<ApplicationInfo>; 
    ApplicationInfo payload = e.Options.Payload as ApplicationInfo; 
    if ( e.Options.Status == DragStatus.DragComplete ) 
    { 
        if ( payload != null && itemsSource.Contains( payload ) ) 
        { 
            itemsSource.Remove( payload ); 
        } 
    } 
}    

public void OnDragCompleted(object sender, Telerik.Windows.DragDrop.DragDropCompletedEventArgs args) 
{ 
    if (args.Effects != DragDropEffects.Scroll && args.Effects != DragDropEffects.Move) 
    { 
        var sourceControl = sender as ListBox; 
        var sourceItems = sourceControl.ItemsSource as IList; 
        var draggedData = DragDropPayloadManager.GetDataFromObject(args.Data, "DragData"); 
 
        if (sourceItems != null) 
        { 
            sourceItems.Remove(draggedData); 
        } 
    } 
}    

The Drop event in DragDropManager corresponds to the DropInfo event with status DropCompleted.

private void OnDropInfo( object sender, DragDropEventArgs e ) 
{ 
    ItemsControl box = e.Options.Destination as ItemsControl; 
    IList<ApplicationInfo> itemsSource = box.ItemsSource as IList<ApplicationInfo>; 
    ApplicationInfo payload = e.Options.Payload as ApplicationInfo; 
    if ( e.Options.Status == DragStatus.DropComplete ) 
        if ( !itemsSource.Contains( payload ) ) 
            itemsSource.Add( payload ); 
} 

private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs args) 
{ 
    var destinationControl = sender as ListBox; 
    var destinationItems = destinationControl.ItemsSource as IList; 
    var draggedData = DragDropPayloadManager.GetDataFromObject(args.Data, "DragData"); 
 
    if (draggedData != null && args.Effects != DragDropEffects.None) 
    { 
        destinationItems.Add(draggedData); 
    } 
} 

The DragInfo event corresponds to the GiveFeedback event. Basically the GiveFeedback event can be used on the DragSource control to update the Cursor, and the DragEffects for the DragOperation.

The DropInfo event corresponds to the DragOver event of DradDropManager. The DragOver event can be used as a replacement for the DropQuery/Info events for various purposes, one of which is to update the AllowedEffects for the drag drop operation. Works both on Source and Destination.

private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) 
{ 
    if (!(e.OriginalSource is FrameworkElement)) 
    { 
        e.Effects = DragDropEffects.None; 
                e.Handled = true; 
    } 
}    

The CancelDrag event corresponds to the QueryContinueDrag event. The CancelDrag() method logic can be replaced by subscribing to the QueryContinueDrag event and manipulating the Action property in the QueryContinueEventArgs.

The control cursor can be set in the GiveFeedbackEventArgs.

private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args) 
{ 
    args.SetCursor(Cursors.Arrow); 
    args.Handled = true; 
}    

Events without analogue

  • PreviewGiveFeedback

  • PreviewQueryContinueDrag

  • PreviewDragEnter

  • PreviewDragLeave

  • PreviewDragOver

  • PreviewDrop

Missing Functionality

  • There is no AutoScrollBehavior out of the box

  • There is no DragArrow Cue

In this article