private void OverlayElementMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _isMouseDown = true; var canvas = MyVisualTreeHelper.GetParent <Canvas>(_draggedDeviceVisual); _dragStartPoint = e.GetPosition(canvas); canvas.CaptureMouse(); e.Handled = true; }
private void DragStarted() { _isDragging = true; var ui = (UIElement)MyVisualTreeHelper.GetParent <ContentPresenter>(_draggedDeviceVisual); _dragStartLeft = DynamicCanvas.GetLeft(ui); _dragStartTop = DynamicCanvas.GetTop(ui); SelectElement(_draggedDeviceVisual); _overlayElement.IsDragging = true; }
private void DrawingAreaPreviewMouseMove(object sender, MouseEventArgs e) { if (_isMouseDown) { var canvas = MyVisualTreeHelper.GetParent <ItemsControl>((FrameworkElement)e.Source); if ((_isDragging == false) && ((Math.Abs(e.GetPosition(canvas).X - _dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(e.GetPosition(canvas).Y - _dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance))) { DragStarted(); } if (_isDragging) { DragMoved(canvas); } } }
private void DrawingAreaPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var vsender = MyVisualTreeHelper.GetParent(((FrameworkElement)e.OriginalSource), x => x.Focusable, x => x.DataContext is ISelectableElement); if (vsender.Focusable && !_isDragging) { return; } if (_isMouseDown) { _isMouseDown = false; } if (_isDragging) { DragFinished(false); e.Handled = true; } Mouse.Capture(null); }
private void DragFinished(bool cancelled) { Mouse.Capture(null); lock (_updaterLock) { if (_isDragging) { if (cancelled == false) { var ui = (UIElement)MyVisualTreeHelper.GetParent <ContentPresenter>(_draggedDeviceVisual); DynamicCanvas.SetTop(ui, _dragStartTop + _overlayElement.TopOffset); DynamicCanvas.SetLeft(ui, _dragStartLeft + _overlayElement.LeftOffset); } SelectElement(_draggedDeviceVisual); _overlayElement.IsDragging = false; } _isDragging = false; _isMouseDown = false; } }
private void DrawingAreaPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var vsender = MyVisualTreeHelper.GetParent(((FrameworkElement)e.OriginalSource), x => x.Focusable, x => x.DataContext is ISelectableElement); if (vsender == null) { SelectElement(null); return; } if (vsender.Focusable) { return; } var canvas = MyVisualTreeHelper.GetParent <ItemsControl>((FrameworkElement)e.Source); _isMouseDown = true; _dragStartPoint = e.GetPosition(canvas); _draggedDeviceVisual = vsender; SelectElement(vsender); canvas.CaptureMouse(); e.Handled = true; }