void StartDrag(MouseEventArgs args) { IDataObject data = null; UIElement dragelement = null; // ADD THE DATA if (_callback != null) { DragDataWrapper dw = new DragDataWrapper(); data = new DataObject(typeof(DragDataWrapper).ToString(), dw); if ((_callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0) { _callback.AppendData(ref data, args); } if ((_callback.SupportedActions & DragDropProviderActions.Data) != 0) { dw.Data = _callback.GetData(); } if ((_callback.SupportedActions & DragDropProviderActions.Visual) != 0) { dragelement = _callback.GetVisual(args); } else { dragelement = args.OriginalSource as UIElement; } dw.Source = _dragSource; dw.Shim = _callback; } else { dragelement = args.OriginalSource as UIElement; data = new DataObject(typeof(UIElement).ToString(), dragelement); } // mwa changed from: // if (dragelement == null || data == null || dragelement == this._dragSource) if (dragelement == null || data == null) { return; } DragEventHandler dragOver = null; DragEventHandler dragLeave = null; QueryContinueDragEventHandler queryContinue = null; GiveFeedbackEventHandler giveFeedback = null; DragDropEffects effects = GetDragDropEffects(); DragDropEffects resultEffects; // Inprocess Drag ... if (DragScope != null) { bool previousAllowDrop = DragScope.AllowDrop; _adorner = new DragAdorner(DragScope, (UIElement)dragelement, true, Opacity); _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual); _layer.Add(_adorner); if (DragScope != _dragSource) { DragScope.AllowDrop = true; System.Windows.DragDrop.AddPreviewDragOverHandler((DependencyObject)DragScope, dragOver = new DragEventHandler(DragScope_DragOver)); System.Windows.DragDrop.AddPreviewDragLeaveHandler(DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave)); System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag)); } try { IsDragging = true; this._mouseLeftScope = false; resultEffects = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects); DragFinished(resultEffects); } catch { } if (DragScope != _dragSource) { DragScope.AllowDrop = previousAllowDrop; System.Windows.DragDrop.RemovePreviewDragOverHandler(DragScope, dragOver); System.Windows.DragDrop.RemovePreviewDragLeaveHandler(DragScope, dragLeave); System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, queryContinue); } } else { System.Windows.DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag)); System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, giveFeedback = new GiveFeedbackEventHandler(onGiveFeedback)); IsDragging = true; CreateDragDropWindow(dragelement); this._dragdropWindow.Show(); try { resultEffects = System.Windows.DragDrop.DoDragDrop(_dragSource, data, effects); } finally { } DestroyDragDropWindow(); System.Windows.DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, onQueryContinueDrag); System.Windows.DragDrop.AddGiveFeedbackHandler(_dragSource, onGiveFeedback); IsDragging = false; DragFinished(resultEffects); } }
void StartDrag(MouseEventArgs args) { IDataObject data = null; UIElement dragelement = null; // ADD THE DATA if (_callback != null) { DragDataWrapper dw = new DragDataWrapper(); data = new DataObject(typeof(DragDataWrapper).ToString(), dw); if ((_callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0) { _callback.AppendData(ref data, args); } if ((_callback.SupportedActions & DragDropProviderActions.Data) != 0) { dw.Data = _callback.GetData(); } if ((_callback.SupportedActions & DragDropProviderActions.Visual) != 0) { dragelement = _callback.GetVisual(args); } else { dragelement = args.OriginalSource as UIElement; } dw.Source = _dragSource; dw.Shim = _callback; // System.Diagnostics.Debug.Assert(DragScope == null, "The DragDataWrapper is meant for in-proc... Sorry for asserting, just wanted to confirm.. comment out assertion if needed"); } else { dragelement = args.OriginalSource as UIElement; data = new DataObject(typeof(UIElement).ToString(), dragelement); } if (dragelement == null || data == null || dragelement == this._dragSource) { return; } #if DEBUG // Add it as Text ... good for testing purposes if (!data.GetDataPresent(DataFormats.Text)) { data.SetData(DataFormats.Text, "abcd"); } #endif DragEventHandler dragOver = null; DragEventHandler dragLeave = null; QueryContinueDragEventHandler queryContinue = null; GiveFeedbackEventHandler giveFeedback = null; DragDropEffects effects = GetDragDropEffects(); DragDropEffects resultEffects; // Inprocess Drag ... if (DragScope != null) { bool previousAllowDrop = DragScope.AllowDrop; _adorner = new DragAdorner(DragScope, (UIElement)dragelement, true, Opacity); _layer = AdornerLayer.GetAdornerLayer(DragScope as Visual); _layer.Add(_adorner); if (DragScope != _dragSource) { DragScope.AllowDrop = true; DragDrop.AddPreviewDragOverHandler((DependencyObject)DragScope, dragOver = new DragEventHandler(DragScope_DragOver)); DragDrop.AddPreviewDragLeaveHandler(DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave)); DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag)); } try { IsDragging = true; this._mouseLeftScope = false; resultEffects = DragDrop.DoDragDrop(_dragSource, data, effects); DragFinished(resultEffects); } catch { System.Diagnostics.Debug.Assert(false); } if (DragScope != _dragSource) { DragScope.AllowDrop = previousAllowDrop; DragDrop.RemovePreviewDragOverHandler(DragScope, dragOver); DragDrop.RemovePreviewDragLeaveHandler(DragScope, dragLeave); DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, queryContinue); } } else { DragDrop.AddPreviewQueryContinueDragHandler(_dragSource, queryContinue = new QueryContinueDragEventHandler(onQueryContinueDrag)); DragDrop.AddGiveFeedbackHandler(_dragSource, giveFeedback = new GiveFeedbackEventHandler(onGiveFeedback)); IsDragging = true; CreateDragDropWindow(dragelement); this._dragdropWindow.Show(); try { resultEffects = DragDrop.DoDragDrop(_dragSource, data, effects); } finally { } DestroyDragDropWindow(); DragDrop.RemovePreviewQueryContinueDragHandler(_dragSource, onQueryContinueDrag); DragDrop.AddGiveFeedbackHandler(_dragSource, onGiveFeedback); IsDragging = false; DragFinished(resultEffects); } }