Example #1
0
        internal static void StartDrag(object sender, HoldingRoutedEventArgs e, DragDropTrigger trigger, object initializeContext = null)
        {
            var dragDropElement = sender as IDragDropElement;

            if (GetRunningOperation(dragDropElement as DependencyObject) != null)
            {
                return;
            }

            var    uiSource = sender as UIElement;
            var    frameworkElementSource = sender as FrameworkElement;
            double leftMargin             = 0d;
            double topMargin = 0d;

            if (frameworkElementSource != null)
            {
                leftMargin = frameworkElementSource.Margin.Left;
                topMargin  = frameworkElementSource.Margin.Top;
            }

            if (dragDropElement == null || !dragDropElement.CanStartDrag(trigger, initializeContext))
            {
                return;
            }

            var context = dragDropElement.DragStarting(trigger, initializeContext);

            var startDragPosition         = e.GetPosition(context.DragSurface.RootElement);
            var relativeStartDragPosition = e.GetPosition(uiSource);

            relativeStartDragPosition = new Point(relativeStartDragPosition.X + leftMargin, relativeStartDragPosition.Y + topMargin);
            var dragPositionMode = DragDrop.GetDragPositionMode(uiSource);

            AddOperation(new DragDropOperation(context, dragDropElement, dragPositionMode, null, startDragPosition, relativeStartDragPosition));
        }
Example #2
0
        internal static void StartDrag(object sender, PointerRoutedEventArgs e, DragDropTrigger trigger, object initializeContext = null)
        {
            var dragDropElement = sender as IDragDropElement;
            var uiSource        = sender as UIElement;

            if (dragDropElement == null)
            {
                dragDropElement = ElementTreeHelper.FindVisualAncestor <IDragDropElement>(uiSource);
            }

            if (GetRunningOperation(dragDropElement as DependencyObject) != null)
            {
                return;
            }

            UIElement uiDragDropElement = dragDropElement as UIElement;

            var    frameworkElementSource = dragDropElement as FrameworkElement;
            double leftMargin             = 0d;
            double topMargin = 0d;

            if (frameworkElementSource != null)
            {
                leftMargin = frameworkElementSource.Margin.Left;
                topMargin  = frameworkElementSource.Margin.Top;
            }

            if (dragDropElement == null || !dragDropElement.CanStartDrag(trigger, initializeContext))
            {
                return;
            }

            var context = dragDropElement.DragStarting(trigger, initializeContext);

            if (context == null)
            {
                return;
            }

            var startDragPosition         = e.GetCurrentPoint(context.DragSurface.RootElement).Position;
            var relativeStartDragPosition = e.GetCurrentPoint(uiDragDropElement).Position;
            var dragPositionMode          = DragDrop.GetDragPositionMode(uiDragDropElement);

            AddOperation(new DragDropOperation(context, dragDropElement, dragPositionMode, e.Pointer, startDragPosition, relativeStartDragPosition));
        }
Example #3
0
        internal static void StartDrag(object sender, PointerRoutedEventArgs e)
        {
            var dragDropElement = sender as IDragDropElement;
            var uiSource        = sender as UIElement;

            if (dragDropElement == null || !dragDropElement.CanStartDrag())
            {
                return;
            }

            var context = dragDropElement.DragStarting();

            var startDragPosition         = e.GetCurrentPoint(context.DragSurface.RootElement).Position;
            var relativeStartDragPosition = e.GetCurrentPoint(uiSource).Position;
            var dragPositionMode          = DragDrop.GetDragPositionMode(uiSource);

            runningOperations.Add(new DragDropOperation(context, dragDropElement, dragPositionMode, e.Pointer, startDragPosition, relativeStartDragPosition));
        }