Esempio n. 1
0
		public void DoDragDrop(IDataObject dataObject, UIElement dragSource, bool showDragVisual, bool useVisualBrush, DragDropEffects effects)
		{
			if (!IsDragging)
			{
				_useDefaultCursor = true;
				_dragScope = Application.Current.MainWindow.Content as FrameworkElement;
				bool previousDrop = _dragScope.AllowDrop;
				_dragScope.AllowDrop = true;

				_dragScope.PreviewDragOver += DragScope_PreviewDragOver;
				_dragScope.DragOver += DragScope_DragOver;
				_dragScope.DragLeave += DragScope_DragLeave;
				_dragScope.DragEnter += DragScope_DragEnter;
				_dragScope.GiveFeedback += DragSource_GiveFeedback;
				_dragScope.QueryContinueDrag += DragScope_QueryContinueDrag;

				var _layer = AdornerLayer.GetAdornerLayer(_dragScope);
				if (showDragVisual)
				{
					_dragAdorner = new DragAdorner(_dragScope, dragSource, useVisualBrush);
					_layer.Add(_dragAdorner);
				}

				IsDragging = true;
				_dragHasLeftScope = false;
				dragSource.CaptureMouse();
				DragDropEffects de = System.Windows.DragDrop.DoDragDrop(dragSource, dataObject, effects);
				dragSource.ReleaseMouseCapture();

				if (_dragAdorner != null)
				{
					_layer.Remove(_dragAdorner);
					_dragAdorner = null;
				}
				_dragScope.AllowDrop = previousDrop;

				_dragScope.GiveFeedback -= DragSource_GiveFeedback;
				_dragScope.DragLeave -= DragScope_DragLeave;
				_dragScope.DragLeave -= DragScope_DragEnter;
				_dragScope.QueryContinueDrag -= DragScope_QueryContinueDrag;
				_dragScope.DragOver -= DragScope_DragOver;
				_dragScope.PreviewDragOver -= DragScope_PreviewDragOver;

				IsDragging = false;
			}
		}
Esempio n. 2
0
		public void DoDragDropSimulate(IDataObject dataObject, UIElement dragSource, bool showDragVisual, bool useVisualBrush, DragDropEffects effects, Action callback)
		{
			if (!IsDragging)
			{
				_dataObject = dataObject;
				_callback = callback;
				_useDefaultCursor = true;
				_dragScope = Application.Current.MainWindow.Content as FrameworkElement;
				_previousDrop = _dragScope.AllowDrop;
				_dragScope.AllowDrop = true;

				_dragScope.PreviewMouseLeftButtonUp += DragScope_PreviewMouseLeftButtonUp;
				_dragScope.MouseMove += DragScope_MouseMove;
				_dragScope.PreviewKeyDown += DragScope_PreviewKeyDown;

				_layer = AdornerLayer.GetAdornerLayer(_dragScope);
				if (showDragVisual)
				{
					_dragAdorner = new DragAdorner(_dragScope, dragSource, useVisualBrush);
					_layer.Add(_dragAdorner);
					_dragAdorner.UpdatePosition(Mouse.GetPosition(_dragScope), true);
				}

				_dragSource = dragSource;
				IsDragging = true;
				_dragHasLeftScope = false;
				Mouse.OverrideCursor = Cursors.No;
				dragSource.CaptureMouse();
			}
		}
Esempio n. 3
0
		public void StopDragSimulate(bool cancel)
		{
			if (IsDragging)
			{
				if (_callback != null)
					_callback();
				_dragSource.ReleaseMouseCapture();
				if (_dragAdorner != null)
				{
					_layer.Remove(_dragAdorner);
					_dragAdorner = null;
				}

				_dragScope.PreviewMouseLeftButtonUp -= DragScope_PreviewMouseLeftButtonUp;
				_dragScope.MouseMove -= DragScope_MouseMove;
				_dragScope.PreviewKeyDown -= DragScope_PreviewKeyDown;

				_dragScope.AllowDrop = _previousDrop;
				Mouse.OverrideCursor = null;
				IsDragging = false;
			}
		}