protected override void OnMouseUp(MouseButtonEventArgs e) { if (HitConnector != null) { Connector sourceConnector = this.sourceConnector; Connector sinkConnector = this.HitConnector; Connection newConnection = new Connection(sourceConnector, sinkConnector); Canvas.SetZIndex(newConnection, designerCanvas.Children.Count); this.designerCanvas.Children.Add(newConnection); } if (HitDesignerItem != null) { this.HitDesignerItem.IsDragConnectionOver = false; } if (this.IsMouseCaptured) this.ReleaseMouseCapture(); AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.designerCanvas); if (adornerLayer != null) { adornerLayer.Remove(this); } }
void CreateConnection(DesignerItem newParent, DesignerItem designerItem) { var source = GetItemConnector(newParent, PARENT_CONNECTOR); var sink = GetItemConnector(designerItem, CHILD_CONNECTOR); var connection = new Connection(source, sink); source.Connections.Add(connection); DesignerCanvas.Children.Add(connection); }
public void DrawChild(DesignerItem designerItem, DesignerItem childItem, List<DesignerItem> list) { if (designerItem == null) return; DrawDesignerItem(childItem);/*创建子节点*/ childItem.UpdateLayout(); childItem.SetTemplate(); var top = Canvas.GetTop(designerItem) + designerItem.ActualHeight + list.Sum(x => x.ActualHeight); list.Add(childItem); var left = Canvas.GetLeft(designerItem) + GetOffset(designerItem); Canvas.SetTop(childItem, top); Canvas.SetLeft(childItem, left); SavePosition(childItem); childItem.UpdateLayout(); var source = GetItemConnector(designerItem, PARENT_CONNECTOR); var sink = GetItemConnector(childItem, "Left"); if (source == null || sink == null) return; #region 创建连线 var conn = new Connection(source, sink); /*创建连线*/ DesignerCanvas.Children.Add(conn); /*放到画布上*/ Panel.SetZIndex(conn, -10000); #endregion childItem.CanCollapsed = true; childItem.UpdateExpander(); }
public void CreateHelperConnection(DesignerItem newParent, DesignerItem dragItem) { RemoveHelperConnection(); if (newParent == null) return; var source = GetItemConnector(newParent, PARENT_CONNECTOR); var sink = GetItemConnector(dragItem, CHILD_CONNECTOR); var connection = new Connection(source, sink); connection.toNewParent = true; source.Connections.Add(connection); DesignerCanvas.Children.Add(connection); SetConnectionColor(connection, Brushes.Red); BringToFront(connection); }
/*设定连线颜色*/ void SetConnectionColor(Connection connection, Brush colorBrushes) { _diagramControl.UpdateLayout(); var path = connection.Template.FindName("PART_ConnectionPath", connection) as Path; if (path != null) { path.Stroke = colorBrushes; //path.StrokeThickness = 2; } }
void RemoveConnection(Connection connection) { if (connection.Source != null) connection.Source.Connections.Remove(connection); if (connection.Sink != null) connection.Sink.Connections.Remove(connection); connection.Source = null; connection.Sink = null; DesignerCanvas.Children.Remove(connection); }