public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { Visibility connectorLabelVisibility = Visibility.Collapsed; string labelText = values[0] as string; PointCollection connectorPoints = values[1] as PointCollection; if (!String.IsNullOrEmpty(labelText) && connectorPoints != null) { int maxSegmentStartPoint; if (DesignerGeometryHelper.LongestSegmentLength(connectorPoints, out maxSegmentStartPoint) > Connector.MinConnectorSegmentLengthForLabel) { connectorLabelVisibility = Visibility.Visible; } } return(connectorLabelVisibility); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { Thickness margin = new Thickness(0); PointCollection connectorPoints = values[0] as PointCollection; double labelBorderWidth = (double)values[1]; double labelBorderHeight = (double)values[2]; if (connectorPoints != null) { int longestSegmentIndex; DesignerGeometryHelper.LongestSegmentLength(connectorPoints, out longestSegmentIndex); if (longestSegmentIndex >= 0) { Point labelLocation = DesignerGeometryHelper.MidPointOfLineSegment(connectorPoints[longestSegmentIndex], connectorPoints[longestSegmentIndex + 1]); labelLocation.X = (int)(labelLocation.X - labelBorderWidth / 2 + EPS); labelLocation.Y = (int)(labelLocation.Y - labelBorderHeight / 2 + EPS); margin.Top = labelLocation.Y; margin.Left = labelLocation.X; } } return(margin); }