private void _adorner_MouseUp(object sender, MouseEventArgs e) { //unnamed team edit: added code to turn the sizecanvas() method back on, and call it. //needed to reset the canvas if the adorner causes scrolling. ((GateCanvas)_dropTarget).DisableSizeCanvas = false; ((GateCanvas)_dropTarget).GCScroller.UpdateLayout(); switch (_adorner.AdornerDropState) { case DropState.CanDrop: try { ((Storyboard)_adorner.Resources["canDrop"]).Completed += (s, args) => { _adornerLayer.Children.Clear(); _adornerLayer.Visibility = Visibility.Collapsed; }; ((Storyboard)_adorner.Resources["canDrop"]).Begin(_adorner); // Added position in drop target Point pos = e.GetPosition((IInputElement)_dropTarget); if (ItemDropped != null) { ItemDropped(_adorner, new DragDropEventArgs(_draggedData, pos, _dropTarget)); } } catch (Exception) { } break; case DropState.CannotDrop: try { Storyboard sb = _adorner.Resources["cannotDrop"] as Storyboard; DoubleAnimation aniX = sb.Children[0] as DoubleAnimation; aniX.To = _delta.X; DoubleAnimation aniY = sb.Children[1] as DoubleAnimation; aniY.To = _delta.Y; sb.Completed += (s, args) => { _adornerLayer.Children.Clear(); _adornerLayer.Visibility = Visibility.Collapsed; }; sb.Begin(_adorner); } catch (Exception) { } break; } _draggedData = null; _adornerLayer.PreviewMouseMove -= new MouseEventHandler(_adorner_MouseMove); _adornerLayer.PreviewMouseUp -= new MouseButtonEventHandler(_adorner_MouseUp); if (_adorner != null) { _adorner.ReleaseMouseCapture(); } _adorner = null; _mouseCaptured = false; }
// Drag = mouse down + move by a certain amount private void DragSource_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { _draggedData = null; } if (!_mouseCaptured && _draggedData != null) { // Only drag when user moved the mouse by a reasonable amount. if (DragDropHelper.IsMovementBigEnough(_initialMousePosition, e.GetPosition(_topWindow))) { try { _adorner = (DragDropAdornerBase)GetDragDropControl(sender as DependencyObject); _adorner.DataContext = _draggedData; _adorner.Opacity = 0.7; _adornerLayer.Visibility = Visibility.Visible; _adornerLayer.Children.Add(_adorner); _mouseCaptured = Mouse.Capture(_adorner); Canvas.SetLeft(_adorner, _initialMousePosition.X - 20); Canvas.SetTop(_adorner, _initialMousePosition.Y - 15); _adornerLayer.PreviewMouseMove += new MouseEventHandler(_adorner_MouseMove); _adornerLayer.PreviewMouseUp += new MouseButtonEventHandler(_adorner_MouseUp); } catch (Exception) { // bummer } } } }
private void _adorner_MouseUp(object sender, MouseEventArgs e) { switch (_adorner.AdornerDropState) { case DropState.CanDrop: try { ((Storyboard)_adorner.Resources["canDrop"]).Completed += (s, args) => { _adornerLayer.Children.Clear(); _adornerLayer.Visibility = Visibility.Collapsed; }; ((Storyboard)_adorner.Resources["canDrop"]).Begin(_adorner); // Added position in drop target Point pos = e.GetPosition((IInputElement)_dropTarget); if (ItemDropped != null) ItemDropped(_adorner, new DragDropEventArgs(_draggedData, pos, _dropTarget)); } catch (Exception) { } break; case DropState.CannotDrop: try { Storyboard sb = _adorner.Resources["cannotDrop"] as Storyboard; DoubleAnimation aniX = sb.Children[0] as DoubleAnimation; aniX.To = _delta.X; DoubleAnimation aniY = sb.Children[1] as DoubleAnimation; aniY.To = _delta.Y; sb.Completed += (s, args) => { _adornerLayer.Children.Clear(); _adornerLayer.Visibility = Visibility.Collapsed; }; sb.Begin(_adorner); } catch (Exception) { } break; } _draggedData = null; _adornerLayer.PreviewMouseMove -= new MouseEventHandler(_adorner_MouseMove); _adornerLayer.PreviewMouseUp -= new MouseButtonEventHandler(_adorner_MouseUp); if (_adorner != null) { _adorner.ReleaseMouseCapture(); } _adorner = null; _mouseCaptured = false; }
// Drag = mouse down + move by a certain amount private void DragSource_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Released) _draggedData = null; if (!_mouseCaptured && _draggedData != null) { // Only drag when user moved the mouse by a reasonable amount. if (DragDropHelper.IsMovementBigEnough(_initialMousePosition, e.GetPosition(_topWindow))) { try { _adorner = (DragDropAdornerBase)GetDragDropControl(sender as DependencyObject); _adorner.DataContext = _draggedData; _adorner.Opacity = 0.7; _adornerLayer.Visibility = Visibility.Visible; _adornerLayer.Children.Add(_adorner); _mouseCaptured = Mouse.Capture(_adorner); Canvas.SetLeft(_adorner, _initialMousePosition.X - 20); Canvas.SetTop(_adorner, _initialMousePosition.Y - 15); _adornerLayer.PreviewMouseMove += new MouseEventHandler(_adorner_MouseMove); _adornerLayer.PreviewMouseUp += new MouseButtonEventHandler(_adorner_MouseUp); } catch (Exception) { // bummer } } } }
public static void DropStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { DragDropAdornerBase myclass = (DragDropAdornerBase)d; myclass.StateChangedHandler(d, e); }