protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // if mouse button is not pressed we have no drag operation, ... if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } // but if mouse button is pressed and start point value is set we do have one if (this.dragStartPoint.HasValue) { // create connection adorner DiagramCanvas canvas = GetDiagramCanvas(this); if (canvas != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas); if (adornerLayer != null) { ConnectionNodeAdorner adorner = new ConnectionNodeAdorner(canvas, this); if (adorner != null) { adornerLayer.Add(adorner); e.Handled = true; } } } } }
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseDown(e); // usual selection business DiagramCanvas designer = VisualTreeHelper.GetParent(this) as DiagramCanvas; if (designer != null) { if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None) { if (this.IsSelected) { designer.SelectionService.RemoveFromSelection(this); } else { designer.SelectionService.AddToSelection(this); } } else if (!this.IsSelected) { designer.SelectionService.SelectItem(this); } Focus(); } e.Handled = false; }
public SelectionAdorner(DiagramCanvas DiagramCanvas, Point?dragStartPoint) : base(DiagramCanvas) { this.DiagramCanvas = DiagramCanvas; this.startPoint = dragStartPoint; SelectionPen = new Pen(Brushes.LightSlateGray, 1); SelectionPen.DashStyle = new DashStyle(new double[] { 2 }, 1); }
public ConnectionNodeAdorner(DiagramCanvas designer, ConnectionNode sourceConnectionNode) : base(designer) { this.DiagramCanvas = designer; this.sourceConnectionNode = sourceConnectionNode; drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; this.Cursor = Cursors.Cross; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.DiagramDesigner = ((DiagramDesigner.DiagramCanvas)(target)); return; } this._contentLoaded = true; }
// when the layout changes we update the position property void ConnectionNode_LayoutUpdated(object sender, EventArgs e) { DiagramCanvas designer = GetDiagramCanvas(this); if (designer != null) { //get centre position of this ConnectionNode relative to the DiagramCanvas this.Position = this.TransformToAncestor(designer).Transform(new Point(this.Width / 2, this.Height / 2)); } }
internal ConnectionNodeInfo GetInfo() { ConnectionNodeInfo info = new ConnectionNodeInfo(); info.DiagramElementLeft = DiagramCanvas.GetLeft(this.ParentDiagramElement); info.DiagramElementTop = DiagramCanvas.GetTop(this.ParentDiagramElement); info.DiagramElementSize = new Size(this.ParentDiagramElement.ActualWidth, this.ParentDiagramElement.ActualHeight); info.Orientation = this.Orientation; info.Position = this.Position; return(info); }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); DiagramCanvas canvas = GetDiagramCanvas(this); if (canvas != null) { // position relative to DiagramCanvas this.dragStartPoint = new Point?(e.GetPosition(canvas)); e.Handled = true; } }
private void ShowAdorner() { // the ConnectionAdorner is created once for each Connection if (this.connectionAdorner == null) { DiagramCanvas designer = VisualTreeHelper.GetParent(this) as DiagramCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { this.connectionAdorner = new ConnectionAdorner(designer, this); adornerLayer.Add(this.connectionAdorner); } } this.connectionAdorner.Visibility = Visibility.Visible; }
public ConnectionAdorner(DiagramCanvas designer, Connection connection) : base(designer) { this.DiagramCanvas = designer; adornerCanvas = new Canvas(); this.visualChildren = new VisualCollection(this); this.visualChildren.Add(adornerCanvas); this.connection = connection; this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged); InitializeDragControls(); drawingPen = new Pen(Brushes.LightSlateGray, 1); drawingPen.LineJoin = PenLineJoin.Round; base.Unloaded += new RoutedEventHandler(ConnectionAdorner_Unloaded); }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml)) { DiagramElement newItem = null; Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml))); if (content != null) { newItem = new DiagramElement(); newItem.Content = content; Point position = e.GetPosition(this); if (dragObject.DesiredSize.HasValue) { Size desiredSize = dragObject.DesiredSize.Value; newItem.Width = desiredSize.Width; newItem.Height = desiredSize.Height; DiagramCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2)); DiagramCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2)); } else { DiagramCanvas.SetLeft(newItem, Math.Max(0, position.X)); DiagramCanvas.SetTop(newItem, Math.Max(0, position.Y)); } Canvas.SetZIndex(newItem, this.Children.Count); this.Children.Add(newItem); SetConnectionNodeDecoratorTemplate(newItem); //update selection this.SelectionService.SelectItem(newItem); newItem.Focus(); } e.Handled = true; } }
void Connection_Unloaded(object sender, RoutedEventArgs e) { // do some housekeeping when Connection is unloaded // remove event handler this.Source = null; this.Target = null; // remove adorner if (this.connectionAdorner != null) { DiagramCanvas designer = VisualTreeHelper.GetParent(this) as DiagramCanvas; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Remove(this.connectionAdorner); this.connectionAdorner = null; } } }
public Selection(DiagramCanvas canvas) { this.DiagramCanvas = canvas; }