diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs index 60da36590..9efd9f5a6 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs @@ -31,7 +31,7 @@ namespace Tango.DragAndDrop private static bool _isMouseDown; private static DispatcherTimer _dragTimer; private static Border _dragBorder; - private const int MIN_DRAG_OFFSET = 8; + //private const int MIN_DRAG_OFFSET = 8; #region Events @@ -70,6 +70,37 @@ namespace Tango.DragAndDrop #region Attached Properties + #region MinDragOffset + + /// <summary> + /// Determines whether an element is MinDragOffset by the drag and drop service. + /// </summary> + public static readonly DependencyProperty MinDragOffsetProperty = + DependencyProperty.RegisterAttached("MinDragOffset", + typeof(int), typeof(DragAndDropService), + new FrameworkPropertyMetadata(8)); + /// <summary> + /// Sets the MinDragOffset attached property. + /// </summary> + /// <param name="element">The element.</param> + /// <param name="value">if set to <c>true</c> [value].</param> + public static void SetMinDragOffset(FrameworkElement element, int value) + { + element.SetValue(MinDragOffsetProperty, value); + } + + /// <summary> + /// Gets the MinDragOffset attached property. + /// </summary> + /// <param name="element">The element.</param> + /// <returns></returns> + public static int GetMinDragOffset(FrameworkElement element) + { + return (int)element.GetValue(MinDragOffsetProperty); + } + + #endregion + #region Draggable /// <summary> @@ -414,7 +445,7 @@ namespace Tango.DragAndDrop /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private static void DragTimer_Tick(object sender, EventArgs e) { - if (Mouse.LeftButton == MouseButtonState.Pressed && _currentDragedElement != null) + if ((Mouse.LeftButton == MouseButtonState.Pressed) && _currentDragedElement != null) { DragStarted?.Invoke(_currentDragedElement, _currentDragedElement); @@ -667,19 +698,19 @@ namespace Tango.DragAndDrop /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param> private static void Draggable_MouseMove(object sender, MouseOrTouchEventArgs e) { - Debug.WriteLine(e.GetPosition(_currentDragedElement)); - if (_isMouseDown) { FrameworkElement element = _currentDragedElement; + int minDragOffset = GetMinDragOffset(element); + if (element != null) { var surface = GetDraggingSurface(element); if (surface != null) { - if ((e.GetPosition(element).X > _mouseDownLocation.X + MIN_DRAG_OFFSET || e.GetPosition(element).X < _mouseDownLocation.X - MIN_DRAG_OFFSET) || (e.GetPosition(element).Y > _mouseDownLocation.Y + MIN_DRAG_OFFSET || e.GetPosition(element).Y < _mouseDownLocation.Y - MIN_DRAG_OFFSET)) + if ((e.GetPosition(element).X > _mouseDownLocation.X + minDragOffset || e.GetPosition(element).X < _mouseDownLocation.X - minDragOffset) || (e.GetPosition(element).Y > _mouseDownLocation.Y + minDragOffset || e.GetPosition(element).Y < _mouseDownLocation.Y - minDragOffset)) { element.ReleaseMouseCapture(); surface.ReleaseMouseCapture(); |
