Ejemplo n.º 1
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.º 2
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.º 3
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;
            }
        }
Ejemplo n.º 4
0
        void PageDesign_KeyUp(object sender, KeyEventArgs e)
        {
            //if (e.Key == Key.Delete)
            //{
            //    DeleteCurrentSelectedControl();
            //    return;
            //}
            //-->修改xaml里的值。
            double newTop  = (double)dr.GetValue(Canvas.TopProperty);
            double newLeft = (double)dr.GetValue(Canvas.LeftProperty);
            ControlModifyPropertyEventArgs ce = new ControlModifyPropertyEventArgs();

            ce.DictProperty = new Dictionary <string, object>();
            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}", _CurrentDesignCtrl.Name);
            _ControlPositionMethod(this, ce);
        }