static void Fe_MouseEnter(object sender, MouseEventArgs e) { if (((FrameworkElement)sender).DataContext is DesignerItemViewModelBase) { DesignerItemViewModelBase designerItem = (DesignerItemViewModelBase)((FrameworkElement)sender).DataContext; designerItem.ShowConnectors = true; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null) { (DataContext as IDiagramViewModel).ClearSelectedItemsCommand.Execute(null); Point position = e.GetPosition(this); DesignerItemViewModelBase itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(dragObject.ContentType); itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2); itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2); itemBase.IsSelected = true; (DataContext as IDiagramViewModel).AddItemCommand.Execute(itemBase); } e.Handled = true; }
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation) : base(orientation) { this.DataItem = dataItem; }
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; }