Create custom connection cap

4 posts, 0 answers
  1. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 07 Dec 2015 Link to this post

    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
  2. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 08 Dec 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 08 Dec 2015 in reply to Kiril Vandov Link to this post

    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

     

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 11 Dec 2015 Link to this post

    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
Back to Top