Example #1
0
 private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     switch (e.PropertyName)
     {
     case "Left":
     case "Top":
         SourceA = PointHelper.GetPointForConnector(this.SourceConnectorInfo);
         if (this.SinkConnectorInfo is FullyCreatedConnectorInfo)
         {
             SourceB = PointHelper.GetPointForConnector((FullyCreatedConnectorInfo)this.SinkConnectorInfo);
         }
         break;
     }
 }
Example #2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (SourceConnector != null)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Point currentPoint = e.GetPosition(this);
                    partialConnection.SinkConnectorInfo = new PartCreatedConnectionInfo(currentPoint);
                    HitTesting(currentPoint);
                }
            }
            else
            {
                // if mouse button is not pressed we have no drag operation, ...
                if (e.LeftButton != MouseButtonState.Pressed)
                {
                    rubberbandSelectionStartPoint = null;
                    initialDragPoint = null;
                }

                if (this.initialDragPoint.HasValue && this.DataContext is DesignerItemViewModelBase)
                {
                    Mouse.SetCursor(Cursors.SizeAll);
                    DesignerItemViewModelBase item = (DesignerItemViewModelBase)this.DataContext;
                    double minLeft      = double.MaxValue;
                    double minTop       = double.MaxValue;
                    Point  currentPoint = e.GetPosition(this);

                    IDiagramViewModel designerCanvas = item.Parent as IDiagramViewModel;
                    Rect rekt = PointHelper.GetBoundingRectangle(designerCanvas.Items, 10);

                    double left = item.Left;
                    double top  = item.Top;
                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);

                    double deltaHorizontal = Math.Max(-minLeft, currentPoint.X - initialDragPoint.Value.X);
                    double deltaVertical   = Math.Max(-minTop, currentPoint.Y - initialDragPoint.Value.Y);
                    item.Left += deltaHorizontal;
                    item.Top  += deltaVertical;

                    if (item.Parent is IDiagramViewModel && item.Parent is DesignerItemViewModelBase)
                    {
                        DesignerItemViewModelBase groupItem = (DesignerItemViewModelBase)item.Parent;
                        if (item.Left + item.ItemWidth >= groupItem.ItemWidth)
                        {
                            item.Left = groupItem.ItemWidth - item.ItemWidth;
                        }
                        if (item.Top + item.ItemHeight >= groupItem.ItemHeight)
                        {
                            item.Top = groupItem.ItemHeight - item.ItemHeight;
                        }
                    }
                    e.Handled = true;
                }
                else
                {
                    // ... but if mouse button is pressed and start
                    // point value is set we do have one
                    if (this.rubberbandSelectionStartPoint.HasValue)
                    {
                        // create rubberband adorner
                        AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                        if (adornerLayer != null)
                        {
                            RubberbandAdorner adorner = new RubberbandAdorner(this, rubberbandSelectionStartPoint);
                            if (adorner != null)
                            {
                                adornerLayer.Add(adorner);
                            }
                        }
                    }
                }
            }
            e.Handled = true;
        }