private void OnDragInitialize(object sender, DragInitializeEventArgs args) { args.AllowedEffects = DragDropEffects.All; if (args.OriginalSource.GetType() == typeof(Telerik.Windows.Controls.RadListBoxItem)) { var draggedShape = (args.OriginalSource as Telerik.Windows.Controls.RadListBoxItem).ChildrenOfType<RadDiagramShapeBase>().FirstOrDefault(); if (draggedShape != null) { var shapeSize = new Size(draggedShape.ActualWidth, draggedShape.ActualHeight); if (shapeSize.Width > 0 && shapeSize.Height > 0) { var dropInfo = new DiagramDropInfo(shapeSize, SerializationService.Default.SerializeItems(new List<IDiagramItem> {draggedShape})); args.Data = dropInfo; args.DragVisualOffset = new Point(args.RelativeStartPoint.X - (shapeSize.Width / 2), args.RelativeStartPoint.Y - (shapeSize.Height / 2)); var draggingImage = new System.Windows.Controls.Image { Source = new Telerik.Windows.Media.Imaging.RadBitmap(draggedShape).Bitmap, Width = shapeSize.Width, Height = shapeSize.Height }; args.DragVisual = draggingImage; } } } }
private static void OnDragInitialize(object sender, DragInitializeEventArgs args) { var container = args.OriginalSource as RadListBoxItem; if (container != null) { var toolboxItem = container.Content as IToolboxItem; if (toolboxItem != null) { var shape = toolboxItem.CreateShape(); if (shape != null) { var element = container.Content as FrameworkElement; if (element != null) { var shapeSize = new Size(element.ActualWidth, element.ActualHeight); var dragDropInfo = new DiagramDropInfo(shapeSize, SerializationService.Default.SerializeItems(new[] { shape })); args.Data = dragDropInfo; args.DragVisualOffset = new Point(args.RelativeStartPoint.X - (shapeSize.Width / 2), args.RelativeStartPoint.Y - (shapeSize.Height / 2)); args.DragVisual = new Image { Source = new RadBitmap(element).Bitmap, Width = shapeSize.Width, Height = shapeSize.Height }; } } args.AllowedEffects = DragDropEffects.All; args.Handled = true; } } else { args.Cancel = true; } }