Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public PageDesign()
        {
            InitializeComponent();
            if (null == cvsPanle)
            {
                cvsPanle = new PCCanvas();
                //b_canvas.Child = cvsPanle;
            }
            dr                   = cvsPanle.dr;
            txtHide              = cvsPanle.txtHide;
            line_Top             = cvsPanle.line_Top;
            line_Left            = cvsPanle.line_Left;
            line_Top.Visibility  = Visibility.Collapsed;
            line_Left.Visibility = Visibility.Collapsed;

            dr.MouseMove           += dr_MouseMove;
            dr.MouseLeftButtonDown += dr_MouseLeftButtonDown;
            dr.MouseLeftButtonUp   += dr_MouseLeftButtonUp;
            dr.MouseLeftUp         += dr_MouseLeftUp;
            dr.ResizeChanged       += dr_ResizeChanged;
            dr.Visibility           = Visibility.Collapsed;

            cvsPanle.MouseLeftButtonUp += cvsPanle_MouseLeftButtonUp;
            this.Loaded      += PageDesign_Loaded;
            this.SizeChanged += PageDesign_SizeChanged;

            this.MouseRightButtonDown += PageDesign_MouseRightButtonDown;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// DesignRectangle控件鼠标左键弹起
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            item.ReleaseMouseCapture();
            mouseVerticalPosition   = -1;
            mouseHorizontalPosition = -1;
            if (null != _CurrentDesignCtrl && !this._CurrentDesignCtrl.Equals(item.Tag as FrameworkElement))
            {
                item.Tag = this._CurrentDesignCtrl;
                SetControlFocus(_CurrentDesignCtrl);
            }
            _IDesigntime.UpdateCurrentSelectedCtrl(this._CurrentDesignCtrl);
            if (isMoveByDesignRectangle)
            {   //-->判断当前选中的控件与
                double newTop  = (double)item.GetValue(Canvas.TopProperty);
                double newLeft = (double)item.GetValue(Canvas.LeftProperty);
                ControlModifyPropertyEventArgs ce = new ControlModifyPropertyEventArgs();
                ce.DictProperty.Add("Canvas.Top", newTop);
                ce.DictProperty.Add("Canvas.Left", newLeft);
                ce.ControlName = string.Format("{0}", _CurrentDesignCtrl.Name);
                _ControlPositionMethod(this, ce);
            }
            isMouseCaptured = false;
            e.Handled       = true;

            line_Top.Visibility  = System.Windows.Visibility.Collapsed;
            line_Left.Visibility = System.Windows.Visibility.Collapsed;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// DesignRectangle控件鼠标左键按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            mouseVerticalPosition   = e.GetPosition(cvsPanle).Y;
            mouseHorizontalPosition = e.GetPosition(cvsPanle).X;
            isMouseCaptured         = true;
            isMoveByDesignRectangle = false;
            item.CaptureMouse();
            e.Handled            = true;
            line_Top.Visibility  = System.Windows.Visibility.Visible;
            line_Left.Visibility = System.Windows.Visibility.Visible;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// DesignRectangle控件大小更变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_ResizeChanged(object sender, ResizeEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            if (null != _CurrentDesignCtrl)
            {
                _CurrentDesignCtrl.Width  = item.Width;
                _CurrentDesignCtrl.Height = item.Height;
                //-->修改top、left的值
                _CurrentDesignCtrl.SetValue(Canvas.LeftProperty, item.GetValue(Canvas.LeftProperty));
                _CurrentDesignCtrl.SetValue(Canvas.TopProperty, item.GetValue(Canvas.TopProperty));
                //-->通知txaml\xml修改
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// DesignRectangle控件上的Auchor控件鼠标左键弹起
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_MouseLeftUp(object sender, MouseButtonEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            if (null != _CurrentDesignCtrl)
            {
                _CurrentDesignCtrl.Width  = item.Width;
                _CurrentDesignCtrl.Height = item.Height;
            }
            ControlModifyPropertyEventArgs ce = new ControlModifyPropertyEventArgs();

            ce.DictProperty.Add("Height", dr.Height);
            ce.DictProperty.Add("Width", dr.Width);
            ce.ControlName = string.Format("{0}", _CurrentDesignCtrl.GetPropertyValue("Name"));// Wrapper.GetPropertyValue(_CurrentDesignCtrl, "Name"));
            _ControlPositionMethod(this, ce);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// DesignRectangle控件移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dr_MouseMove(object sender, MouseEventArgs e)
        {
            DesignRectangle item = sender as DesignRectangle;

            if (isMouseCaptured)
            {
                isMoveByDesignRectangle = true;
                _maxLeft = cvsPanle.ActualWidth - item.Width;
                _maxTop  = cvsPanle.ActualHeight - item.Height;
                var    p       = e.GetPosition(cvsPanle);
                double deltaV  = p.Y - mouseVerticalPosition;
                double deltaH  = p.X - mouseHorizontalPosition;
                double newTop  = deltaV + (double)item.GetValue(Canvas.TopProperty);
                double newLeft = deltaH + (double)item.GetValue(Canvas.LeftProperty);
                newLeft = newLeft > _maxLeft ? _maxLeft : (newLeft < 0 ? 0 : newLeft);
                newTop  = newTop > _maxTop ? _maxTop : (newTop < 0 ? 0 : newTop);
                // Set new position of object.
                item.SetValue(Canvas.TopProperty, newTop);
                item.SetValue(Canvas.LeftProperty, newLeft);

                UpdateLineTopOrLeftPoint(new Point(newLeft + item.Width, newTop));

                if (null != _CurrentDesignCtrl)
                {
                    _CurrentDesignCtrl.SetValue(Canvas.TopProperty, newTop);
                    _CurrentDesignCtrl.SetValue(Canvas.LeftProperty, newLeft);
                    _CurrentDesignCtrl.Width  = item.Width;
                    _CurrentDesignCtrl.Height = item.Height;

                    //-->这里非常耗费资源。当鼠标弹起来的时候,更新会更好些。
                    //ControlModifyPropertyEventArgs ce = new ControlModifyPropertyEventArgs();
                    //ce.DictProperty.Add("Canvas.Top", newTop);
                    //ce.DictProperty.Add("Canvas.Left", newLeft);
                    //ce.DictProperty.Add("Height", dr.Height);
                    //ce.DictProperty.Add("Width", dr.Width);
                    //ce.ControlName = string.Format("{0}", Wrapper.GetPropertyValue(_CurrentDesignCtrl, "Name"));
                    //_ControlPositionMethod(this, ce);
                }
                //Update position global variables.
                mouseVerticalPosition   = e.GetPosition(cvsPanle).Y;
                mouseHorizontalPosition = e.GetPosition(cvsPanle).X;
            }
        }