internal override void OnMouseMove(MouseEventArgs e) { if (!IsLeftButtonDown) { return; } if (draggableItems.Count > 0) { Debug.WriteLine("DragNDropController.InitializeDrag "); isDraggingInProcess = true; try { DragDrop.AddGiveFeedbackHandler(treeViewEx, OnGiveFeedBack); // ToDo add data provided by all nodes selected const DragDropEffects allowedEffects = DragDropEffects.Move | DragDropEffects.None; var d = DragDrop.DoDragDrop(treeViewEx, new DataObject(draggableItems), allowedEffects); DragDrop.RemoveGiveFeedbackHandler(treeViewEx, OnGiveFeedBack); } finally { isDraggingInProcess = false; } } e.Handled = isDraggingInProcess; }
public DraggedItem(ItemVisualizer sourceItemVisualizer) { DropOnStashEffect = DragDropEffects.Move; DropOnInventoryEffect = DragDropEffects.Copy; DropOnBinEffect = DragDropEffects.Move; SourceItemVisualizer = sourceItemVisualizer; var mainWindow = (MetroWindow)Application.Current.MainWindow; var dragScope = (UIElement)mainWindow.Content; var imageSource = sourceItemVisualizer.Item.Image.ImageSource.Result; var brush = new ImageBrush(imageSource) { Opacity = 0.5 }; _dragAdorner = new DragAdorner(dragScope, new Size(imageSource.Width, imageSource.Height), brush); DragStart = Mouse.GetPosition(SourceItemVisualizer); // DragStart is subtracted for the cursor to be on the item image at the same position as where the drag // was initiated. // The window position is subtracted because the cursor position is retrieved as an absolute value. // The title bar height is subtracted because the content used for the adorner does not include it. var winPos = GetWindowPosition(mainWindow); _offset.X = -DragStart.X - winPos.X; _offset.Y = -DragStart.Y - winPos.Y - mainWindow.TitlebarHeight; _adornerLayer = AdornerLayer.GetAdornerLayer(dragScope); _adornerLayer.Add(_dragAdorner); DragDrop.AddGiveFeedbackHandler(sourceItemVisualizer, GiveFeedback); }
public DragDropEffects InitiateDrag(IDataObject dataToDrag, DragDropEffects allowedEffects) { DragDrop.AddGiveFeedbackHandler(mouseDownArgs.Target, GiveFeedback); var ret = DragDrop.DoDragDrop(mouseDownArgs.Target, dataToDrag, allowedEffects); DragDrop.RemoveGiveFeedbackHandler(mouseDownArgs.Target, GiveFeedback); RaiseMouseUpMethod(); return(ret); }
public DragDropEffects InitiateDrag(IDataObject dataToDrag, DragDropEffects allowedEffects) { if (source.Target is not FrameworkElement src) { return(DragDropEffects.None); } DragDrop.AddGiveFeedbackHandler(src, GiveFeedback); var ret = DragDrop.DoDragDrop(src, dataToDrag, allowedEffects); DragDrop.RemoveGiveFeedbackHandler(src, GiveFeedback); RaiseMouseUpMethod(src); return(ret); }
public void DoDragDropNewConnection(IConnectionLineSource sourceWidget, OperatorPart output) { _dragStartPositionOnCanvas = Win32RawInput.MousePointInUiElement(_cgv.XOperatorCanvas); _snappedToValidInput = false; var dragData = new DataObject(CONNECTION_LINE_OUTPUT_IDENTIFIER, output); // We have to restart the temp connection, because DoDragDrop triggers DragCompleted Start(_dragStartPositionOnCanvas, sourceWidget, output.Func.EvaluationIndex); DragDrop.AddGiveFeedbackHandler(_cgv, GiveFeedbackHandler); DragDrop.DoDragDrop(_cgv, dragData, DragDropEffects.All); // Importat! This line is not reached until drop is completed. DragDrop.RemoveGiveFeedbackHandler(_cgv, GiveFeedbackHandler); Stop(new Vector(), null); }
public void DoDragDropRewireConnection(ConnectionLine cl) { _dragStartPositionOnCanvas = Win32RawInput.MousePointInUiElement(_cgv.XOperatorCanvas); _snappedToValidInput = false; var dragData = new DataObject(CONNECTION_LINE_OUTPUT_IDENTIFIER, cl.Output); // We have to restart the temp connection, because DoDragDrop triggers DragCompleted cl.HitTestDisabledDuringDrag = false; RewireExistingConnection(cl, _dragStartPositionOnCanvas, cl.Output.Func.EvaluationIndex); DragDrop.AddGiveFeedbackHandler(_cgv, GiveFeedbackHandler); DragDrop.DoDragDrop(_cgv, dragData, DragDropEffects.All); // Important! This line is not reached until drop is completed. DragDrop.RemoveGiveFeedbackHandler(_cgv, GiveFeedbackHandler); Stop(new Vector(), null); }
private void uiAudioList_MouseMove(object sender, MouseEventArgs e) { if (ShouldStartDrag(e)) { this.isDragging = true; var item = this.draggedItem.DataContext as IAudioListItemViewModel; Debug.Assert(item != null); if (item.ShowLyrics) { item.SwitchLyricsStateCommand.Execute(null); } var capturePoint = e.GetPosition(this.draggedItem); this.draggedItemAdorner = new DragAdorner(this.dragScope, this.draggedItem, true, capturePoint, 0.7); layer = AdornerLayer.GetAdornerLayer(this.dragScope); layer.Add(this.draggedItemAdorner); this.draggedItem.Visibility = System.Windows.Visibility.Collapsed; DragDrop.AddPreviewDragOverHandler(this.dragScope, DragScopeDragOver); DragDrop.AddGiveFeedbackHandler(this.dragScope, DragScopeGiveFeedback); try { DragDrop.DoDragDrop(this.draggedItem, item, DragDropEffects.Move); this.draggedItem.CaptureMouse(); } finally { DragDrop.RemovePreviewDragOverHandler(this.dragScope, DragScopeDragOver); DragDrop.RemoveGiveFeedbackHandler(this.dragScope, DragScopeGiveFeedback); this.draggedItem.Visibility = System.Windows.Visibility.Visible; if (layer != null && this.draggedItemAdorner != null) { layer.Remove(this.draggedItemAdorner); } this.draggedItemAdorner = null; this.draggedItem = null; this.isDragging = false; } } }
public DraggedItem(ItemVisualizer sourceItemVisualizer) { DropOnStashEffect = DragDropEffects.Move; DropOnInventoryEffect = DragDropEffects.Copy; DropOnBinEffect = DragDropEffects.Move; SourceItemVisualizer = sourceItemVisualizer; var mainWindow = (MetroWindow)Application.Current.MainWindow; var dragScope = (UIElement)mainWindow.Content; var imageSource = sourceItemVisualizer.Item.Image.ImageSource.Result; var brush = new ImageBrush(imageSource) { Opacity = 0.5 }; _dragAdorner = new DragAdorner(dragScope, new Size(imageSource.Width, imageSource.Height), brush); DragStart = Mouse.GetPosition(SourceItemVisualizer); // DragStart is subtracted for the cursor to be on the item image at the same position as where the drag // was initiated. // The window position is subtracted because the cursor position is retrieved as an absolute value. // The title bar height is subtracted because the content used for the adorner does not include it. var winPos = GetWindowPosition(mainWindow); _offset.X = -DragStart.X - winPos.X; _offset.Y = -DragStart.Y - winPos.Y - mainWindow.TitlebarHeight; _adornerLayer = AdornerLayer.GetAdornerLayer(dragScope); _adornerLayer.Add(_dragAdorner); // Win32.GetCursorPos() returns logical pixels, WPF uses physical/device pixels. // Need to scale from logical to physical if user has a custom UI scaling. _uiScaling = PresentationSource.FromVisual(_dragAdorner).CompositionTarget.TransformToDevice; DragDrop.AddGiveFeedbackHandler(sourceItemVisualizer, GiveFeedback); }
private void StartDrag(MouseEventArgs args) { IDataObject data = null; UIElement dragelement = null; // ADD THE DATA if (this.Callback != null) { DragDataWrapper dw = new DragDataWrapper(); data = new DataObject(typeof(DragDataWrapper).ToString(), dw); if ((this.Callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0) { this.Callback.AppendData(ref data, args); } if ((this.Callback.SupportedActions & DragDropProviderActions.Data) != 0) { dw.Data = this.Callback.GetData(); } if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0) { dragelement = this.Callback.GetVisual(args); } else { dragelement = args.OriginalSource as UIElement; } dw.Source = this.DragSource; dw.Shim = this.Callback; Debug.Assert(this.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; } DragEventHandler dragOver = null; DragEventHandler dragLeave = null; QueryContinueDragEventHandler queryContinue = null; GiveFeedbackEventHandler giveFeedback = null; DragDropEffects effects = this.GetDragDropEffects(); DragDropEffects resultEffects; // Inprocess Drag ... if (this.DragScope != null) { bool previousAllowDrop = this.DragScope.AllowDrop; this.adorner = new DragAdorner(this.DragScope, (UIElement)dragelement, true, this.Opacity); this.layer = AdornerLayer.GetAdornerLayer(this.DragScope as Visual); this.layer.Add(this.adorner); if (this.DragScope != this.DragSource) { this.DragScope.AllowDrop = true; DragDrop.AddPreviewDragOverHandler((DependencyObject)this.DragScope, dragOver = new DragEventHandler(DragScope_DragOver)); DragDrop.AddPreviewDragLeaveHandler(this.DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave)); DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag)); } try { this.IsDragging = true; this.mouseLeftScope = false; resultEffects = DragDrop.DoDragDrop(this.DragSource, data, effects); this.DragFinished(resultEffects); } catch { Debug.Assert(false); } if (this.DragScope != this.DragSource) { this.DragScope.AllowDrop = previousAllowDrop; DragDrop.RemovePreviewDragOverHandler(this.DragScope, dragOver); DragDrop.RemovePreviewDragLeaveHandler(this.DragScope, dragLeave); DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, queryContinue); } } else { DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag)); DragDrop.AddGiveFeedbackHandler(this.DragSource, giveFeedback = new GiveFeedbackEventHandler(OnGiveFeedback)); this.IsDragging = true; if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0) { this.CreateDragDropWindow(dragelement); this.dragdropWindow.Show(); } try { resultEffects = DragDrop.DoDragDrop(this.DragSource, data, effects); } finally { } if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0) { this.DestroyDragDropWindow(); } DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, OnQueryContinueDrag); DragDrop.AddGiveFeedbackHandler(this.DragSource, OnGiveFeedback); this.IsDragging = false; this.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); } }