title | page_title | description | slug | tags | published | position |
---|---|---|---|---|---|---|
DragDropManager Migration |
DragDropManager Migration |
Check our "DragDropManager Migration" documentation article for the DragDropManager {{ site.framework_name }} control. |
dragdropmanager-migration |
dragdropmanager,migration |
true |
5 |
The article explains the events of the DragDropManager.
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:
{{region dragdropmanager-migration_0}} 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; } {{endregion}}
{{region dragdropmanager-migration_1}} 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 };
}
{{endregion}}
The event corresponding to the DragInfo event in RadDragAndDropManager is now DragDropComplete. The DragDropComplete event is the equivalent of the DragQuery with status DropComplete.
{{region dragdropmanager-migration_2}} private void OnDragInfo( object sender, DragDropEventArgs e ) { ListBoxItem listBoxItem = e.Options.Source as ListBoxItem; ListBox box = ItemsControl.ItemsControlFromItemContainer( listBoxItem ) as ListBox; IList itemsSource = box.ItemsSource as IList; ApplicationInfo payload = e.Options.Payload as ApplicationInfo; if ( e.Options.Status == DragStatus.DragComplete ) { if ( payload != null && itemsSource.Contains( payload ) ) { itemsSource.Remove( payload ); } } } {{endregion}}
{{region dragdropmanager-migration_3}} 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);
}
}
}
{{endregion}}
The Drop event in DragDropManager corresponds to the DropInfo event with status DropCompleted.
{{region dragdropmanager-migration_4}} private void OnDropInfo( object sender, DragDropEventArgs e ) { ItemsControl box = e.Options.Destination as ItemsControl; IList itemsSource = box.ItemsSource as IList; ApplicationInfo payload = e.Options.Payload as ApplicationInfo; if ( e.Options.Status == DragStatus.DropComplete ) if ( !itemsSource.Contains( payload ) ) itemsSource.Add( payload ); } {{endregion}}
{{region dragdropmanager-migration_5}} 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);
}
}
{{endregion}}
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.
{{region dragdropmanager-migration_6}} private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e) { if (!(e.OriginalSource is FrameworkElement)) { e.Effects = DragDropEffects.None; e.Handled = true; } } {{endregion}}
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.
{{region dragdropmanager-migration_7}} private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args) { args.SetCursor(Cursors.Arrow); args.Handled = true; } {{endregion}}
-
PreviewGiveFeedback
-
PreviewQueryContinueDrag
-
PreviewDragEnter
-
PreviewDragLeave
-
PreviewDragOver
-
PreviewDrop
-
There is no AutoScrollBehavior out of the box
-
There is no DragArrow Cue