Beispiel #1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Thickness       margin          = new Thickness(0);
            PointCollection connectorPoints = values[0] as PointCollection;
            // 8 and 4 is calcuated from the margin / padding settings related to the label in xaml
            double labelBorderWidth  = (double)values[1] + 8;
            double labelBorderHeight = (double)values[2] + 4;

            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);
        }