views:

34

answers:

1

Hello, in Silverlight 3 for Mobile, how do I get at a Path's figure points, so I can ultimately get at it's Points (X, Y coordinates)? From what I've been reading, it sounds like the tree structures of the PathGeometry isn't stored in Silverlight 3 for Mobile (I'm doing this for WP7)... Is there another way around this? All I want is the Points collection of the Path. Below is the code I've written to parse the Path's Segments to get at the Points, BUT, the Figures collection is always empty, so I can't even get at the Segments. I've also tried using XamlReader.load to read in the Path XAML, but that has the same results, an empty Figures collection. I've also pasted the Path XAML below.

Thanks for reading, and hope someone can point me in the right direction :) Tim

    private List<Point> getShapePathPoints(Path shapePath)
    {
        List<Point> shapePathPoints = new List<Point>();

        PathGeometry pathGeometry = (PathGeometry)shapePath.Data;
        foreach (PathFigure pathFigure in pathGeometry.Figures)
        {

            foreach (PolyLineSegment segment in pathFigure.Segments)
            {
                foreach (Point point in segment.Points)
                {
                    shapePathPoints.Add(point);
                }
            }
        }

        return shapePathPoints;
    }
A: 

Figures and Segements are a high level programmatic way to define a path. They do not represent the internal storage used by the path itself since in general they are not memory efficient.

The Mini path language that is used to define the vast majority of paths is a form of serialisation for the actual internal representation of a path. When such paths are created the programmatic sets of Figures are not generated.

It would have been a nice addition to the API to have a method that could reverse engineer a mini language path back to a set of figures but as usual, nice to haves need to weighed against cost.

Your options are:-

  • use Xaml that includes Figures and Segment instances rather then the mini path language
  • use XmlReader or XDocument to load the Xaml containing paths, find the path of interest, parse the mini language yourself.
AnthonyWJones
Thank you, that confirms what I've been seeing, and reading. As you can tell I'm new to Silverlight and XAML... I'm an ASP.NET, Service, and SQL developer :) But I'm starting to get used to it from this small project. I've gone another route, creating my own boundry path algorithm. XmlReader doesn't work with paths created in mini path language, I bet it will work for Path's with Figures added manually as you mention though.
Tim