How to get Points from RadDiagramShape

3 posts, 1 answers
  1. Jeevan
    Jeevan avatar
    5 posts
    Member since:
    Jan 2014

    Posted 26 Feb 2014 Link to this post

    Hi 

    Is there some way by which we can get the points on a RadDiagramShape. 
    Currently we see that the RadDiagramShape has Geometry property. Is there some way to get a PointCollection from the shape.
    eg Is it possible to get the four points of a rectangle represented by  RadDiagramShape.

    Regards
    Jeevan
  2. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 28 Feb 2014 Link to this post

    Hello Jeevan,

    Thank you for your question.

    You cannot get a collection of Points from a RadDiagramShape out of the box. However, this can be achieved by using some custom logic. In order to do it you will need to get the flattened PathGeometry of the Shape with the GetFlattenedPathGeometry() method. Then you should get every Point of every PathSegment in the PathGeometry.

    In the next few lines I will try to explain how exactly you can get those points. Let's begin with that e
    very PathGeometry has a collection of PathFigures and every PathFigure in this collection has a PathSegments collection. When the collection is flattened the PathSegments collection contains only PolylineSegments and every one of those segments has a collection of Points which you may use to achieve your requirement. Here is an example in code:
    private void GetGeometryPoints(IGeometryShape shape)
    {
        PathGeometry pathGeometry = shape.Geometry.GetFlattenedPathGeometry();
     
        var pointCollection = new List<Point>();
     
        foreach (PathFigure figure in pathGeometry.Figures)
        {
            foreach (PathSegment segment in figure.Segments)
            {
                var polySegment = segment as PolyLineSegment;
                if (polySegment != null)
                {
                    foreach (Point point in polySegment.Points)
                    {
                        Point newPoint = new Point
                        {
                            X = point.X + this.Shape1.Position.X,
                            Y = point.Y + this.Shape1.Position.Y
                        };
                        pointCollection.Add(newPoint);
                    }
                }
            }
        }
    }

    I also attached a sample project with the described approach. 

    Regards,
    Martin
    Telerik
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeevan
    Jeevan avatar
    5 posts
    Member since:
    Jan 2014

    Posted 17 Mar 2014 in reply to Martin Link to this post

    Thanks Martin.
Back to Top