diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.DragAndDrop')
| -rw-r--r-- | Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs index 9efd9f5a6..4473e2879 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs @@ -31,6 +31,7 @@ namespace Tango.DragAndDrop private static bool _isMouseDown; private static DispatcherTimer _dragTimer; private static Border _dragBorder; + private static TouchDevice _touchDevice; //private const int MIN_DRAG_OFFSET = 8; #region Events @@ -445,15 +446,24 @@ 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 || (_touchDevice != null && _touchDevice.IsActive)) && _currentDragedElement != null) { DragStarted?.Invoke(_currentDragedElement, _currentDragedElement); var surface = GetDraggingSurface(_currentDragedElement); var rootElement = surface.Parent as FrameworkElement; - DraggingSurface.SetLeft(_dragBorder, Mouse.GetPosition(surface).X - _mouseDownLocation.X); - DraggingSurface.SetTop(_dragBorder, Mouse.GetPosition(surface).Y - _mouseDownLocation.Y); + if (_touchDevice != null) + { + DraggingSurface.SetLeft(_dragBorder, _touchDevice.GetTouchPoint(surface).Position.X - _mouseDownLocation.X); + DraggingSurface.SetTop(_dragBorder, _touchDevice.GetTouchPoint(surface).Position.Y - _mouseDownLocation.Y); + } + else + { + DraggingSurface.SetLeft(_dragBorder, Mouse.GetPosition(surface).X - _mouseDownLocation.X); + DraggingSurface.SetTop(_dragBorder, Mouse.GetPosition(surface).Y - _mouseDownLocation.Y); + } + _dragBorder.Visibility = Visibility.Visible; bool found = false; @@ -475,7 +485,16 @@ namespace Tango.DragAndDrop Rect dropRect = new Rect(dropPoint, new Size(dropElementScaledSize.X, dropElementScaledSize.Y)); Rect dragRect = new Rect(Canvas.GetLeft(_dragBorder), Canvas.GetTop(_dragBorder), _dragBorder.Width / 2, _dragBorder.Height); - Point mousePoint = rootElement.PointToScreen(Mouse.GetPosition(rootElement)); + Point mousePoint = new Point(); + + if (_touchDevice != null) + { + mousePoint = rootElement.PointToScreen(_touchDevice.GetTouchPoint(rootElement).Position); + } + else + { + mousePoint = rootElement.PointToScreen(Mouse.GetPosition(rootElement)); + } if (dropRect.IntersectsWith(new Rect(mousePoint, new Size(1, 1)))) { @@ -723,6 +742,7 @@ namespace Tango.DragAndDrop _isMouseDown = false; CreateDraggingElement(); + _touchDevice = e.TouchDevice; _dragTimer.Start(); SetIsDragging(element, true); } @@ -742,6 +762,8 @@ namespace Tango.DragAndDrop if (element != null) { + e.Handled = true; + if ((e.GetPosition(element).X > _mouseDownLocation.X + 10 || e.GetPosition(element).X < _mouseDownLocation.X - 10) || (e.GetPosition(element).Y > _mouseDownLocation.Y + 10 || e.GetPosition(element).Y < _mouseDownLocation.Y - 10)) { DropDraggable(); |
