Exemple #1
0
        /// <summary>
        /// Drag in canvas
        /// </summary>
        /// <param name="dragTarget">drag target</param>
        /// <param name="dragElement">drag element</param>
        /// <param name="bound">bound</param>
        /// <returns></returns>
        public static bool BindDrag(this FrameworkElement dragTarget, FrameworkElement dragElement, DragBound bound, Action <Point, bool> positonChangeCallback = null)
        {
            bool result = false;

            if (dragTarget.Parent != null && (dragTarget.Parent as Canvas) != null)
            {
                Canvas moveCvs = dragTarget.Parent as Canvas;

                Point          positionOnElement = new Point();
                bool           isDrag            = false;
                int            deviceId          = 0;
                DragBoundCheck check             = new DragBoundCheck(dragTarget, bound);
                dragElement.PreviewTouchDown += delegate(object sender, TouchEventArgs e)
                {
                    IDrag dragObj = dragTarget as IDrag;
                    if (dragObj != null && dragObj.IsDrag == false)
                    {
                        return;
                    }
                    if (isDrag == false)
                    {
                        deviceId          = e.TouchDevice.Id;
                        positionOnElement = e.GetTouchPoint(dragTarget).Position;
                        isDrag            = true;
                        dragElement.CaptureTouch(e.TouchDevice);
                    }
                };
                dragElement.PreviewTouchMove += delegate(object sender, TouchEventArgs e)
                {
                    if (isDrag && e.TouchDevice.Id == deviceId)
                    {
                        SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, false, e);
                    }
                };


                dragElement.PreviewTouchUp += delegate(object sender, TouchEventArgs e)
                {
                    if (isDrag && deviceId == e.TouchDevice.Id)
                    {
                        isDrag = false;
                        SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, true, e);
                        dragElement.ReleaseTouchCapture(e.TouchDevice);
                    }
                };
                result = true;
            }
            return(result);
        }
Exemple #2
0
 public DragBoundCheck(FrameworkElement element, DragBound bound)
 {
     this.element = element;
     this.bound   = bound;
 }
Exemple #3
0
        public static bool BindDrag(this FrameworkElement dragTarget, Action <Point, bool> positonChangeCallback = null)
        {
            DragBound bound = new DragBound();

            return(BindDrag(dragTarget, bound, positonChangeCallback));
        }