예제 #1
0
        private void OnElementMoving(_Control element, Rect rect)
        {
            if (!DesginCanvas.IsAutoAlign)
            {
                return;
            }
            List <AutoAlignLine> alignLines = new List <AutoAlignLine>();

            foreach (UIElement ui in DesginCanvas.Children)
            {
                if (DesginCanvas.SelectedControls.Contains(ui as _Control))
                {
                    continue;
                }
                if (ui is _Control && !(ui is _Line))
                {
                    AutoAlignLine alignLine = AlignCanvas.MeasureAlign(element, ui as _Control);
                    if (!alignLine.IsEmpty)
                    {
                        alignLines.Add(alignLine);
                    }
                }
            }

            AlignCanvas.DrawAlignLines(alignLines);
        }
예제 #2
0
        private void OnElementMoved(_Control element, Rect rect)
        {
            AlignCanvas.Clear();

            if (!DesginCanvas.IsAutoAlign)
            {
                return;
            }

            foreach (UIElement ui in DesginCanvas.Children)
            {
                if (DesginCanvas.SelectedControls.Contains(ui as _Control))
                {
                    continue;
                }
                if (ui is _Control)
                {
                    AutoAlignLine alignLine = AlignCanvas.MeasureAlign(element, ui as _Control);
                    if (!alignLine.IsEmpty)
                    {
                        switch (alignLine.AlignType)
                        {
                        case AlignType.Left:
                            element.Left = alignLine.X1;
                            break;

                        case AlignType.Top:
                            element.Top = alignLine.Y1;
                            break;

                        case AlignType.Right:
                            element.Left = alignLine.X1 - element.Width;
                            break;

                        case AlignType.Bottom:
                            element.Top = alignLine.Y1 - element.Height;
                            break;

                        case AlignType.HorizontalCenter:
                            element.Left = alignLine.X1 - element.Width / 2d;
                            break;

                        case AlignType.VerticalCenter:
                            element.Top = alignLine.Y1 - element.Height / 2d;
                            break;
                        }
                        break;
                    }
                }
            }
        }