static void DragStarted(UIElement uiElt) { try { _isMouseDown = false; Mouse.Capture(uiElt); DragSourceBase advisor = GetDragSource(uiElt as DependencyObject); DataObject data = advisor.GetDataObject(_draggedElt); data.SetData("OffsetPoint", _offsetPoint); DragDropEffects supportedEffects = advisor.SupportedEffects; // Perform DragDrop DragDropEffects effects = System.Windows.DragDrop.DoDragDrop(_draggedElt, data, supportedEffects); advisor.FinishDrag(_draggedElt, effects); // Clean up RemovePreviewAdorner(); Mouse.Capture(null); _draggedElt = null; } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "DragStarted()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs"); } }
private static void OnDragSourceChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args) { try { UIElement sourceElt = depObj as UIElement; if (args.NewValue != null && args.OldValue == null) { sourceElt.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(DragSource_PreviewMouseLeftButtonDown); sourceElt.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove); sourceElt.PreviewMouseUp += new MouseButtonEventHandler(DragSource_PreviewMouseUp); // Set the Drag source UI DragSourceBase advisor = args.NewValue as DragSourceBase; advisor.SourceUI = sourceElt; } else if (args.NewValue == null && args.OldValue != null) { sourceElt.PreviewMouseLeftButtonDown -= DragSource_PreviewMouseLeftButtonDown; sourceElt.PreviewMouseMove -= DragSource_PreviewMouseMove; sourceElt.PreviewMouseUp -= DragSource_PreviewMouseUp; } } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "OnDragSourceChanged()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs"); } }
/* ____________________________________________________________________ * Drag Source events * ____________________________________________________________________ */ static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { // Make this the new drag source DragSourceBase advisor = GetDragSource(sender as DependencyObject); if (advisor.IsDraggable(e.Source as UIElement) == false) { return; } _draggedElt = e.Source as UIElement; _dragStartPoint = e.GetPosition(GetTopContainer()); _offsetPoint = e.GetPosition(_draggedElt); _isMouseDown = true; } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "DragSource_PreviewMouseLeftButtonDown()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs"); } }