Пример #1
0
        protected override void OnDragStarted(double horizontalOffset, double verticalOffset)
        {
            TargetLayer.GuidelineFilter.Push(GetSizeGuidableLines);

            beginSize = (Vector)TargetElement.RenderSize;

            if (TargetLayer.Parent is IStoryboard)
            {
                beginPosition = new Vector(
                    Canvas.GetLeft(TargetElement),
                    Canvas.GetTop(TargetElement));
            }
            else
            {
                var position = TargetElement.TranslatePoint(new Point(0, 0), (UIElement)TargetElement.Parent);

                beginThickness       = TargetLayer.GetParentLayoutInfo().Margin;
                beginTargetThickness = TargetElement.Margin;

                beginThickness.Left *= -1;
                beginThickness.Top  *= -1;

                beginBound = new Rect(position, (Size)beginSize);
            }

            positionLimit = new Vector(
                beginPosition.X + beginSize.X - TargetElement.GetDesignMinWidth(),
                beginPosition.Y + beginSize.Y - TargetElement.GetDesignMinHeight());

            base.OnDragStarted(horizontalOffset, verticalOffset);
        }
Пример #2
0
        private double SizingHeight(double deltaY)
        {
            double height = Math.Max(
                TargetElement.GetDesignMinHeight(),
                beginSize.Y + deltaY);

            TargetLayer.SetHeight(height);

            return(height);
        }
Пример #3
0
        private void OnPanelDragDelta(double deltaX, double deltaY)
        {
            bool hasSizingLeft =
                ResizeDirection == ResizeGripDirection.Left ||
                ResizeDirection == ResizeGripDirection.BottomLeft ||
                ResizeDirection == ResizeGripDirection.TopLeft;

            bool hasSizingRight =
                ResizeDirection == ResizeGripDirection.Right ||
                ResizeDirection == ResizeGripDirection.BottomRight ||
                ResizeDirection == ResizeGripDirection.TopRight;

            bool hasSizingTop =
                ResizeDirection == ResizeGripDirection.Top ||
                ResizeDirection == ResizeGripDirection.TopLeft ||
                ResizeDirection == ResizeGripDirection.TopRight;

            bool hasSizingBottom =
                ResizeDirection == ResizeGripDirection.Bottom ||
                ResizeDirection == ResizeGripDirection.BottomLeft ||
                ResizeDirection == ResizeGripDirection.BottomRight;

            Thickness margin       = beginTargetThickness;
            var       parentLayout = TargetLayer.GetParentLayoutInfo();

            if (hasSizingTop)
            {
                switch (TargetLayer.GripLayer.ClipData.VerticalAlignment)
                {
                case VerticalAlignment.Center:
                    SizingHeight(-deltaY * 2);
                    break;

                case VerticalAlignment.Stretch:
                    margin.Bottom = beginThickness.Bottom;
                    margin.Top    = Math.Min(
                        beginThickness.Top + deltaY,
                        parentLayout.Bound.Height - beginThickness.Bottom - TargetElement.GetDesignMinHeight());
                    break;

                case VerticalAlignment.Top:
                {
                    double sizedHeight = SizingHeight(-deltaY);
                    margin.Top = beginBound.Bottom - sizedHeight;
                }
                break;

                case VerticalAlignment.Bottom:
                {
                    double sizedHeight = SizingHeight(-deltaY);
                    margin.Top = Math.Min(parentLayout.Bound.Height - sizedHeight - margin.Bottom, 0);
                }
                break;
                }
            }

            if (hasSizingBottom)
            {
                switch (TargetLayer.GripLayer.ClipData.VerticalAlignment)
                {
                case VerticalAlignment.Center:
                    SizingHeight(deltaY * 2);
                    break;

                case VerticalAlignment.Stretch:
                    margin.Bottom = Math.Min(
                        beginThickness.Bottom - deltaY,
                        parentLayout.Bound.Height - beginThickness.Top - TargetElement.GetDesignMinHeight());
                    break;

                case VerticalAlignment.Top:
                case VerticalAlignment.Bottom:
                {
                    SizingHeight(deltaY);

                    margin.Bottom = Math.Min(
                        beginThickness.Bottom - deltaY,
                        parentLayout.Bound.Height - beginThickness.Top - TargetElement.GetDesignMinHeight());

                    if (TargetLayer.GripLayer.ClipData.VerticalAlignment == VerticalAlignment.Top)
                    {
                        margin.Bottom = Math.Min(margin.Bottom, 0);
                    }

                    // 부모가 스택인경우 처리
                    if (this.TargetLayer.Parent.Model is PStackLayout stack &&
                        stack.Orientation == Core.POrientation.Vertical)
                    {
                        margin.Bottom = beginThickness.Bottom;
                    }
                }
                break;
                }
            }

            if (hasSizingLeft)
            {
                switch (TargetLayer.GripLayer.ClipData.HorizontalAlignment)
                {
                case HorizontalAlignment.Center:
                    SizingWidth(-deltaX * 2);
                    break;

                case HorizontalAlignment.Stretch:
                    margin.Right = beginThickness.Right;
                    margin.Left  = Math.Min(
                        beginThickness.Left + deltaX,
                        parentLayout.Bound.Width - beginThickness.Right - TargetElement.GetDesignMinWidth());
                    break;

                case HorizontalAlignment.Left:
                {
                    double sizedWidth = SizingWidth(-deltaX);
                    margin.Left = beginBound.Right - sizedWidth;
                }
                break;

                case HorizontalAlignment.Right:
                {
                    double sizedWidth = SizingWidth(-deltaX);
                    margin.Left = Math.Min(parentLayout.Bound.Width - sizedWidth - margin.Right, 0);
                }
                break;
                }
            }

            if (hasSizingRight)
            {
                switch (TargetLayer.GripLayer.ClipData.HorizontalAlignment)
                {
                case HorizontalAlignment.Center:
                    SizingWidth(deltaX * 2);
                    break;

                case HorizontalAlignment.Stretch:
                    margin.Right = Math.Min(
                        beginThickness.Right - deltaX,
                        parentLayout.Bound.Width - beginThickness.Left - TargetElement.GetDesignMinWidth());
                    break;

                case HorizontalAlignment.Left:
                case HorizontalAlignment.Right:
                {
                    double sizedWidth = SizingWidth(deltaX);

                    margin.Right = Math.Min(
                        beginThickness.Right - deltaX,
                        parentLayout.Bound.Width - beginThickness.Left - TargetElement.GetDesignMinWidth());

                    if (TargetLayer.GripLayer.ClipData.HorizontalAlignment == HorizontalAlignment.Left)
                    {
                        margin.Right = Math.Min(margin.Right, 0);
                    }

                    // 부모가 스택인경우 처리
                    if (this.TargetLayer.Parent.Model is PStackLayout stack &&
                        stack.Orientation == Core.POrientation.Horizontal)
                    {
                        margin.Right = beginThickness.Right;
                    }
                }
                break;
                }
            }

            TargetLayer.SetMargin(margin);
        }