private void OnDragInitialize(object sender, DragInitializeEventArgs e) { var treeViewItem = e.OriginalSource as RadTreeViewItem ?? (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>(); var data = treeViewItem != null? treeViewItem.Item : (sender as RadTreeView).SelectedItem; var payload = DragDropPayloadManager.GeneratePayload(null); var dropDetails = new DropIndicationDetails(); dropDetails.CurrentDraggedItem = data; DragVisual visual = new DragVisual() { Content = dropDetails, ContentTemplate = data is CategoryViewModel ? this.AssociatedObject.Resources["CategoryDragTemplate"] as DataTemplate : this.AssociatedObject.Resources["ProductDragTemplate"] as DataTemplate }; payload.SetData("DraggedData", data); payload.SetData("DropDetails", dropDetails); e.DragVisual = visual; e.DragVisualOffset = e.RelativeStartPoint; e.Data = payload; e.AllowedEffects = DragDropEffects.All; FrameworkElement sourceItem = e.OriginalSource as RadTreeViewItem ?? (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>(); if (sourceItem == null) { this.sourceItems = (IList)this.AssociatedObject.ItemsSource; } else { this.sourceItems = (sourceItem as RadTreeViewItem).ParentItem != null ? (IList)(sourceItem as RadTreeViewItem).ParentItem.ItemsSource : (IList)this.AssociatedObject.ItemsSource; } this.sourceItem = sourceItem.DataContext; this.destinationItems = this.AssociatedObject.ItemsSource as IList; this.isTreeSource = true; }
private void OnDragInitialize(object sender, DragInitializeEventArgs e) { DropIndicationDetails details = new DropIndicationDetails(); var listBoxItem = e.OriginalSource as System.Windows.Controls.ListBoxItem ?? (e.OriginalSource as FrameworkElement).ParentOfType<System.Windows.Controls.ListBoxItem>(); var item = listBoxItem != null ? listBoxItem.DataContext : (sender as System.Windows.Controls.ListBox).SelectedItem; details.CurrentDraggedItem = item; IDragPayload dragPayload = DragDropPayloadManager.GeneratePayload(null); dragPayload.SetData("DraggedData", item); dragPayload.SetData("DropDetails", details); e.Data = dragPayload; e.DragVisual = new DragVisual() { Content = details, ContentTemplate = this.AssociatedObject.Resources["DraggedItemTemplate"] as DataTemplate }; e.DragVisualOffset = e.RelativeStartPoint; e.AllowedEffects = DragDropEffects.All; }