示例#1
0
        private void OnDragDelta(object sender, DragDeltaEventArgs e)
        {
            if (!GetTargetIsEditable())
            {
                e.Handled = true;
                return;
            }

            CustomThumb thumb = e.OriginalSource as CustomThumb;

            if (thumb == null)
            {
                return;
            }

            double VerticalChange   = e.VerticalChange;
            double HorizontalChange = e.HorizontalChange;

            Rect NewBound = Rect.Empty;

            if (thumb.DragDirection == DragDirection.MiddleCenter)
            {
                NewBound = DragElement(HorizontalChange, VerticalChange);
            }
            else
            {
                NewBound = ResizeElement(thumb, HorizontalChange, VerticalChange);
            }

            RaisenDragChangingEvent(NewBound);
            SetTargetActualBound(NewBound);

            e.Handled = true;
        }
示例#2
0
        private Rect ResizeElement(CustomThumb HitedThumb, double HorizontalChange, double VerticalChange)
        {
            #region Get Old Value

            if (HitedThumb == null)
            {
                return(Rect.Empty);
            }


            Rect TargetActualBound = GetTargetActualBound();

            double TopOld    = CorrectDoubleValue(TargetActualBound.Y);
            double LeftOld   = CorrectDoubleValue(TargetActualBound.X);
            double WidthOld  = CorrectDoubleValue(TargetActualBound.Width);
            double HeightOld = CorrectDoubleValue(TargetActualBound.Height);

            double TopNew    = TopOld;
            double LeftNew   = LeftOld;
            double WidthNew  = WidthOld;
            double HeightNew = HeightOld;

            #endregion

            if (HitedThumb.DragDirection == DragDirection.TopLeft ||
                HitedThumb.DragDirection == DragDirection.MiddleLeft ||
                HitedThumb.DragDirection == DragDirection.BottomLeft)
            {
                ResizeFromLeft(DragHelperParent, LeftOld, WidthOld, HorizontalChange, out LeftNew, out WidthNew);
            }

            if (HitedThumb.DragDirection == DragDirection.TopLeft ||
                HitedThumb.DragDirection == DragDirection.TopCenter ||
                HitedThumb.DragDirection == DragDirection.TopRight)
            {
                ResizeFromTop(DragHelperParent, TopOld, HeightOld, VerticalChange, out TopNew, out HeightNew);
            }

            if (HitedThumb.DragDirection == DragDirection.TopRight ||
                HitedThumb.DragDirection == DragDirection.MiddleRight ||
                HitedThumb.DragDirection == DragDirection.BottomRight)
            {
                ResizeFromRight(DragHelperParent, LeftOld, WidthOld, HorizontalChange, out WidthNew);
            }

            if (HitedThumb.DragDirection == DragDirection.BottomLeft ||
                HitedThumb.DragDirection == DragDirection.BottomCenter ||
                HitedThumb.DragDirection == DragDirection.BottomRight)
            {
                ResizeFromBottom(DragHelperParent, TopOld, HeightOld, VerticalChange, out HeightNew);
            }

            this.Width  = WidthNew;
            this.Height = HeightNew;
            Canvas.SetTop(this, TopNew);
            Canvas.SetLeft(this, LeftNew);

            return(new Rect
            {
                X = LeftNew,
                Y = TopNew,
                Width = WidthNew,
                Height = HeightNew
            });
        }
示例#3
0
        private Rect ResizeElement(CustomThumb HitedThumb, double HorizontalChange, double VerticalChange)
        {
            #region Get Old Value

            if (HitedThumb == null)
            {
                return(Rect.Empty);
            }

            this.HorizontalDelta += (int)HorizontalChange;
            this.VerticalDelta   += (int)VerticalChange;

            Rect TargetActualBound = GetTargetActualBound();

            //System.Console.WriteLine(string.Format("HorizontalDelta:{0},VerticalDelta:{1}", HorizontalDelta, VerticalDelta));

            //如果偏移小于阈值,不重置大小
            if ((this.HorizontalChangeThreshold != 0 && this.VerticalChangeThreshold != 0) &&
                (this.HorizontalDelta / this.HorizontalChangeThreshold != 0 &&
                 this.VerticalDelta / this.VerticalChangeThreshold != 0))
            {
                return(TargetActualBound);
            }

            if (this.HorizontalChangeThreshold > 0)
            {
                this.HorizontalDelta = this.HorizontalDelta / this.HorizontalChangeThreshold != 0 ?
                                       (this.HorizontalDelta >= this.HorizontalChangeThreshold ? this.HorizontalChangeThreshold : -this.HorizontalChangeThreshold) : 0;
            }
            if (this.VerticalChangeThreshold > 0)
            {
                this.VerticalDelta = this.VerticalDelta / this.VerticalChangeThreshold != 0 ?
                                     (this.VerticalDelta >= this.VerticalChangeThreshold ? this.VerticalChangeThreshold : -this.VerticalChangeThreshold) : 0;
            }

            double TopOld    = CorrectDoubleValue(TargetActualBound.Y);
            double LeftOld   = CorrectDoubleValue(TargetActualBound.X);
            double WidthOld  = CorrectDoubleValue(TargetActualBound.Width);
            double HeightOld = CorrectDoubleValue(TargetActualBound.Height);

            double TopNew    = TopOld;
            double LeftNew   = LeftOld;
            double WidthNew  = WidthOld;
            double HeightNew = HeightOld;

            //System.Console.WriteLine(string.Format("HorizontalDelta:{0},VerticalDelta:{1}", HorizontalDelta, VerticalDelta));
            #endregion

            if (HitedThumb.DragDirection == DragDirection.TopLeft ||
                HitedThumb.DragDirection == DragDirection.MiddleLeft ||
                HitedThumb.DragDirection == DragDirection.BottomLeft)
            {
                this.ResizeFromLeft(DragHelperParent, LeftOld, WidthOld, this.HorizontalDelta, out LeftNew, out WidthNew);
            }

            if (HitedThumb.DragDirection == DragDirection.TopLeft ||
                HitedThumb.DragDirection == DragDirection.TopCenter ||
                HitedThumb.DragDirection == DragDirection.TopRight)
            {
                this.ResizeFromTop(DragHelperParent, TopOld, HeightOld, this.VerticalDelta, out TopNew, out HeightNew);
            }

            if (HitedThumb.DragDirection == DragDirection.TopRight ||
                HitedThumb.DragDirection == DragDirection.MiddleRight ||
                HitedThumb.DragDirection == DragDirection.BottomRight)
            {
                this.ResizeFromRight(DragHelperParent, LeftOld, WidthOld, this.HorizontalDelta, out WidthNew);
            }

            if (HitedThumb.DragDirection == DragDirection.BottomLeft ||
                HitedThumb.DragDirection == DragDirection.BottomCenter ||
                HitedThumb.DragDirection == DragDirection.BottomRight)
            {
                this.ResizeFromBottom(DragHelperParent, TopOld, HeightOld, this.VerticalDelta, out HeightNew);
            }

            this.Width  = WidthNew;
            this.Height = HeightNew;
            Canvas.SetTop(this, TopNew);
            Canvas.SetLeft(this, LeftNew);

            this.HorizontalDelta = 0;
            this.VerticalDelta   = 0;

            return(new Rect
            {
                X = LeftNew,
                Y = TopNew,
                Width = WidthNew,
                Height = HeightNew
            });
        }