private void DoDragAndDropEnd(FrameworkElement dropTarget)
        {
            //  Get the event handler.
            DragAndDropDelegate dragAndDropEnd = DragAndDropEnd;

            //  If we have the event handler, fire it.
            if (dragAndDropEnd != null)
            {
                DragAndDropEventArgs args = new DragAndDropEventArgs()
                {
                    Allow       = true,
                    DragSource  = dragSource,
                    DragElement = dragElement,
                    DragData    = dragData,
                    DropTarget  = dropTarget
                };
                dragAndDropEnd(this, args);
            }

            //  We're done.
            dragging    = false;
            dragData    = null;
            dragElement = null;
            dragSource  = null;
            dropTarget  = null;
            dragAdorner = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Continues drag and drop, calling the appropriate event if it is registered.
        /// </summary>
        /// <param name="potentialDropTarget">The potential drop target.</param>
        private void DoContinueDragAndDrop(FrameworkElement potentialDropTarget)
        {
            //  If we have a start handler, call it.
            DragAndDropDelegate dragAndDropContinue = DragAndDropContinue;

            if (dragAndDropContinue != null)
            {
                //  Create the drag and drop event args.
                DragAndDropEventArgs args = new DragAndDropEventArgs()
                {
                    DragSource  = dragSource,
                    DragElement = dragElement,
                    DragData    = dragData,
                    DropTarget  = potentialDropTarget,
                    Allow       = true
                };

                //  Call the event.
                dragAndDropContinue(this, args);

                //  If the operation has been disallowed, return.
                if (args.Allow == false)
                {
                    return;
                }
            }

            //  Store the potential drop target.
            dropTarget = potentialDropTarget;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts drag and drop, calling the appropriate event if it is registered.
        /// </summary>
        /// <param name="dragSource">The drag source.</param>
        /// <param name="dragElement">The drag element.</param>
        /// <param name="dragData">The drag data.</param>
        private void DoDragAndDropStart(FrameworkElement dragSource, FrameworkElement dragElement,
                                        object dragData)
        {
            //  If we have a start handler, call it.
            DragAndDropDelegate dragAndDropStart = DragAndDropStart;

            if (dragAndDropStart != null)
            {
                //  Create the drag args.
                DragAndDropEventArgs args = new DragAndDropEventArgs()
                {
                    DragSource  = dragSource,
                    DragElement = dragElement,
                    DragData    = dragData,
                    Allow       = true
                };

                //  Call the event handler.
                dragAndDropStart(this, args);

                //  Has the operation been disallowed?
                if (args.Allow == false)
                {
                    //  todo extrapolate to function
                    dragging    = false;
                    dragData    = null;
                    dragElement = null;
                    dragSource  = null;
                    dropTarget  = null;
                    dragAdorner = null;
                    return;
                }

                //  Do we have an adorner?
                if (args.DragAdorner != null)
                {
                    //  Add the adorner.
                    dragAdorner = args.DragAdorner;
                    adornerLayer.AddAdorner(dragAdorner);
                }
            }

            //  Allow the drag.
            dragging = true;
        }
        private void DoContinueDragAndDrop(FrameworkElement potentialDropTarget)
        {
            //  If we have a start handler, call it.
            DragAndDropDelegate dragAndDropContinue = DragAndDropContinue;

            if (dragAndDropContinue != null)
            {
                DragAndDropEventArgs args = new DragAndDropEventArgs()
                {
                    DragSource  = dragSource,
                    DragElement = dragElement,
                    DragData    = dragData,
                    DropTarget  = potentialDropTarget,
                    Allow       = true
                };
                dragAndDropContinue(this, args);
                if (args.Allow == false)
                {
                    return;
                }
            }

            dropTarget = potentialDropTarget;
        }
Exemplo n.º 5
0
        void LoadRecognizers()
        {
            if (ElementGestureRecognizers == null)
            {
                return;
            }

#if __MOBILE__
            if (_shouldReceiveTouch == null)
            {
                // Cache this so we don't create a new UITouchEventArgs instance for every recognizer
                _shouldReceiveTouch = ShouldReceiveTouch;
            }
#endif

#if __MOBILE__
            UIDragInteraction uIDragInteraction = null;
            UIDropInteraction uIDropInteraction = null;

            if (_dragAndDropDelegate != null)
            {
                foreach (var interaction in _renderer.NativeView.Interactions)
                {
                    if (interaction is UIDragInteraction uIDrag && uIDrag.Delegate == _dragAndDropDelegate)
                    {
                        uIDragInteraction = uIDrag;
                    }

                    if (interaction is UIDropInteraction uiDrop && uiDrop.Delegate == _dragAndDropDelegate)
                    {
                        uIDropInteraction = uiDrop;
                    }
                }
            }

            bool dragFound = false;
            bool dropFound = false;
#endif
            for (int i = 0; i < ElementGestureRecognizers.Count; i++)
            {
                IGestureRecognizer recognizer = ElementGestureRecognizers[i];
                if (_gestureRecognizers.ContainsKey(recognizer))
                {
                    continue;
                }

                var nativeRecognizer = GetNativeRecognizer(recognizer);
                if (nativeRecognizer != null && _handler != null)
                {
#if __MOBILE__
                    nativeRecognizer.ShouldReceiveTouch = _shouldReceiveTouch;
#endif
                    _handler.AddGestureRecognizer(nativeRecognizer);

                    _gestureRecognizers[recognizer] = nativeRecognizer;
                }

#if __MOBILE__
                if (Forms.IsiOS11OrNewer && recognizer is DragGestureRecognizer)
                {
                    dragFound            = true;
                    _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate();
                    if (uIDragInteraction == null)
                    {
                        var interaction = new UIDragInteraction(_dragAndDropDelegate);
                        interaction.Enabled = true;
                        _renderer.NativeView.AddInteraction(interaction);
                    }
                }

                if (Forms.IsiOS11OrNewer && recognizer is DropGestureRecognizer)
                {
                    dropFound            = true;
                    _dragAndDropDelegate = _dragAndDropDelegate ?? new DragAndDropDelegate();
                    if (uIDropInteraction == null)
                    {
                        var interaction = new UIDropInteraction(_dragAndDropDelegate);
                        _renderer.NativeView.AddInteraction(interaction);
                    }
                }
#endif
            }

#if __MOBILE__
            if (!dragFound && uIDragInteraction != null)
            {
                _renderer.NativeView.RemoveInteraction(uIDragInteraction);
            }

            if (!dropFound && uIDropInteraction != null)
            {
                _renderer.NativeView.RemoveInteraction(uIDropInteraction);
            }
#endif

            var toRemove = _gestureRecognizers.Keys.Where(key => !ElementGestureRecognizers.Contains(key)).ToArray();

            for (int i = 0; i < toRemove.Length; i++)
            {
                IGestureRecognizer gestureRecognizer = toRemove[i];
                var uiRecognizer = _gestureRecognizers[gestureRecognizer];
                _gestureRecognizers.Remove(gestureRecognizer);

                _handler.RemoveGestureRecognizer(uiRecognizer);
                uiRecognizer.Dispose();
            }
        }