Exemplo n.º 1
0
 public RubberbandAdorner(DesignerCanvas designerCanvas, Point? dragStartPoint)
     : base(designerCanvas)
 {
     this._designerCanvas = designerCanvas;
     this._startPoint = dragStartPoint;
     _rubberbandPen = new Pen(Brushes.LightSlateGray, 1);
     _rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
 }
Exemplo n.º 2
0
 public ConnectorAdorner(DesignerCanvas designer, Connector connector)
     : base(designer)
 {
     this._canvas = designer;
     this._connector = connector;
     _drawingPen = new Pen(Brushes.LightSlateGray, 1);
     _drawingPen.LineJoin = PenLineJoin.Round;
     this.Cursor = Cursors.Cross;
 }
Exemplo n.º 3
0
        public ConnectionAdorner(DesignerCanvas designer, Connection connection)
            : base(designer)
        {
            this._designerCanvas = designer;
            this._myCanvas = new Canvas();
            this._visualChildren = new VisualCollection(this);
            this._visualChildren.Add(_myCanvas);

            this._connection = connection;

            InitializeDragThumbs();
        }
Exemplo n.º 4
0
        public ConnectionAdorner(DesignerCanvas designer, Connection connection)
            : base(designer)
        {
            this._designerCanvas = designer;
            this._myCanvas       = new Canvas();
            this._visualChildren = new VisualCollection(this);
            this._visualChildren.Add(_myCanvas);

            this._connection = connection;

            InitializeDragThumbs();
        }
Exemplo n.º 5
0
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);

            //更新选择项。
            var designer = DesignerCanvas.GetOwnerCanvas(this);

            if (designer != null)
            {
                designer.HandleMouseSelection(this);
            }

            e.Handled = false;
        }
Exemplo n.º 6
0
        private DesignerItemContainer[] GetSelectedContainers()
        {
            DesignerItemContainer[] selectedDesignerItems = null;

            var designerItem = this.DataContext as DesignerItemContainer;

            if (designerItem != null && designerItem.IsSelected)
            {
                var designer = DesignerCanvas.GetOwnerCanvas(designerItem);
                if (designer != null)
                {
                    // only resize DesignerItems
                    selectedDesignerItems = designer.SelectedItems.OfType <DesignerItemContainer>().ToArray();
                }
            }
            return(selectedDesignerItems);
        }
Exemplo n.º 7
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            var designerItem = DesignerItemContainer.GetItemContainer(this);

            if (designerItem != null && designerItem.IsSelected)
            {
                var designer = DesignerCanvas.GetOwnerCanvas(designerItem);
                if (designer != null)
                {
                    //只移动 DesignerItem
                    var designerItems = designer.SelectedItems.OfType <DesignerItemContainer>();

                    //以下代码不知何意,暂留。
                    //double minLeft = double.MaxValue;
                    //double minTop = double.MaxValue;

                    //foreach (var item in designerItems)
                    //{
                    //    double left = GetDouble(item, Canvas.LeftProperty);
                    //    double top = GetDouble(item, Canvas.TopProperty);

                    //    minLeft = Math.Min(left, minLeft);
                    //    minTop = Math.Min(top, minTop);
                    //}

                    //double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                    //double deltaVertical = Math.Max(-minTop, e.VerticalChange);

                    double deltaHorizontal = e.HorizontalChange;
                    double deltaVertical   = e.VerticalChange;

                    foreach (var item in designerItems)
                    {
                        double left = GetDouble(item, Canvas.LeftProperty);
                        double top  = GetDouble(item, Canvas.TopProperty);

                        Canvas.SetLeft(item, left + deltaHorizontal);
                        Canvas.SetTop(item, top + deltaVertical);
                    }

                    designer.InvalidateMeasure();

                    e.Handled = true;
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            var dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                var content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));
                if (content != null)
                {
                    var newItem = new DesignerItemContainer();
                    newItem.Content = content;

                    var position = e.GetPosition(this);
                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    this.Children.Add(newItem);

                    this.AddSelection(true, newItem);
                }

                e.Handled = true;
            }
        }
Exemplo n.º 9
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _canvas = this.Template.FindName("PART_DesignerCanvas", this) as DesignerCanvas;
            if (_canvas == null) throw new InvalidProgramException("ModelingDesigner 的模板中必须要有命名为 PART_DesignerCanvas 的 DesignerCanvas 元素。");
            _canvas.SelectionChanged += (o, e) => this.OnSelectionChanged();

            _canvas.DragLineCompleted += _canvas_DragLineCompleted;

            //在首次加载时,把所有元素加入到画布中。
            AddElementsIntoCanvas();
        }