private void Label_box_LostFocus(object sender, RoutedEventArgs e) { var editingObj = _graphViewer.LayoutEditor.EditingObject; if (editingObj == null) { return; } var obj = editingObj.DrawingObject as DrawingObject2; if (obj == null) { return; } if (obj.Label == null) { if (label_box.Text == "") { return; } } else if (obj.Label.Text == label_box.Text) { return; } var node = obj as Node; if (node != null) { _graphViewer.updateVNodeLabelText(editingObj as VNode, label_box.Text); //var sz = Common.MeasureLabel(label); //node.GeometryNode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node,sz.Width,sz.Height ); //(editingObj as VNode).Invalidate(); } else { var edge = obj as Edge; if (edge == null) { return; } var vedge = editingObj as VEdge; var label = edge.Label; if (label == null) { label = new DrawingLabel(label_box.Text); edge.Label = label; label.Owner = edge; //var sz = Common.MeasureLabel(label); //edge.GeometryEdge.Label = new Microsoft.Msagl.Core.Layout.Label(sz.Width, sz.Height, edge.GeometryEdge); var llabel = new LLabel(); edge.GeometryEdge.Label = llabel; llabel.GeometryParent = edge.GeometryEdge; label.GeometryLabel = llabel; //edge.GeometryEdge.Label.UserData = edge.Label; //var fe = _graphViewer.CreateDefaultFrameworkElementForDrawingObject(edge); //var vlabel = new VLabel(edge, fe); //fe.Tag = vlabel; //(editingObj as VEdge).VLabel = vlabel; _graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); _graphViewer.LayoutEditor.AttachLayoutChangeEvent(vedge.VLabel); } else { label.Text = label_box.Text; var textBlock = _graphViewer.drawingObjectsToFrameworkElements[edge] as TextBlock; textBlock.Text = label.Text; //textBlock.InvalidateMeasure(); textBlock.Width = Double.NaN; textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Width = textBlock.DesiredSize.Width; //textBlock.Height = textBlock.DesiredSize.Height; //label.GeometryLabel.Width } //var vedge = _graphViewer.GetIViewerObject(edge) as VEdge; //_graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); _graphViewer.AssignLabelWidthHeight(edge.GeometryEdge, edge); //_graphViewer.LayoutEditor.AttachLayoutChangeEvent(vedge.VLabel); //var labelCol = new List<LLabel>(); //labelCol.Add(label.GeometryLabel); //EdgeLabelPlacement lp = new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph,labelCol);//,label.GeometryLabel) //var lp=new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph, new List<LLabel> { label.GeometryLabel}); var lp = new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph, new [] { label.GeometryLabel }); lp.Run(); vedge.Invalidate(); //edge.LabelText = label_box.Text; //var vedge = _graphViewer.GetIViewerObject(edge) as VEdge; //_graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); //vedge.Invalidate(); } //if (label.Text == label_box.Text) // return; //label.Text = label_box.Text; //obj.Label = label; }