This is a migrated thread and some comments may be shown as answers.

Create custom connection cap

3 Answers 33 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Geoffrey
Top achievements
Rank 1
Geoffrey asked on 07 Dec 2015, 10:18 AM

Hello

I try to custom connection caps, you can find in attach files my goals and what i did.

I try 2 solutions with a custom RadDiagramConnection : 

- Override CreateSourceCapGeometry and Target : i didn't find a way to add a text into a pathFigure (not like geometryGroup and FormattedText)

- Override CreateGeometry : I works fine but the style of the line (like StrokeDashArray) is also use for the caps (that's why the text look like weird).

Do you think it's possible to do that? Is there any other solution?

 

Thank you in advance.

weird
weird
weird

3 Answers, 1 is accepted

Sort by
0
Kiril Vandov
Telerik team
answered on 08 Dec 2015, 10:56 AM
Hello Geoffrey,

These are the two approaches that you could use to modify the ConnectionCaps of the RadDiagramConnection. Is there a particular reason that you dont want to import the desired text using FormatedText and converting it to Geomerty? :
FormattedText ft = new FormattedText(
    "Caption",
    Thread.CurrentThread.CurrentCulture,
    System.Windows.FlowDirection.LeftToRight,
    new Typeface("Verdana"), 32, Brushes.Black);
 
Geometry geometry = ft.BuildGeometry(midpoint);
Unfortunately you cant simply turn off the StrokeDashArray just for the text.

I hope this information helps.

Kind regards,
Kiril Vandov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Geoffrey
Top achievements
Rank 1
answered on 08 Dec 2015, 01:51 PM

Thanks for your awnser,

 

I use this code for the CreateGeometry override method, but if i want to use this method for CreateSourceCapGeometry, how can I cast the result geometry text to a PathFigure?

 

Thanks

 

0
Martin Ivanov
Telerik team
answered on 11 Dec 2015, 12:54 PM
Hello Geoffrey,

It seems that there is no straight forward approach of converting a geometry to a single PathFigure. To achieve this you can convert the Geometry to PathGeometry and then put all segments of all figures of the geometry to the Segments collection of a new PathFigure object. However, using this approach you will probably need to include additional segments because the final figure won't be the one you are expecting.

Another approach could be to create the formatted text geometry in the CreateGometry() override and merge its Figures collection with the line geometry's Figures. For example:
public class CustomConnection : RadDiagramConnection
{
    private Point targetCapGeometryStart;
 
    protected override System.Windows.Media.PathFigure CreateTargetCapGeometry(System.Windows.Point startPoint, System.Windows.Point endPoint, ref System.Windows.Point baseLineEnd)
    {
        this.targetCapGeometryStart = startPoint;
        return base.CreateTargetCapGeometry(startPoint, endPoint, ref baseLineEnd);
    }
 
    protected override Geometry CreateGeometry(Telerik.Windows.Diagrams.Core.BridgeType bridgeType, bool roundedCorners)
    {
        var geometry = base.CreateGeometry(bridgeType, roundedCorners);
 
        FormattedText formattedText = new FormattedText(
            "Caption",
             Thread.CurrentThread.CurrentCulture,
             System.Windows.FlowDirection.LeftToRight,
             new Typeface("Verdana"), 32, Brushes.Black);
        
        var capGeometry = PathGeometry.CreateFromGeometry(formattedText.BuildGeometry(this.targetCapGeometryStart));
        var pathGeometry = (PathGeometry)geometry;
 
        foreach (var item in capGeometry.Figures)
        {
            pathGeometry.Figures.Add(item);
        }
 
        return pathGeometry;
    }
}

I hope this is useful.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
Geoffrey
Top achievements
Rank 1
Answers by
Kiril Vandov
Telerik team
Geoffrey
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or