开发者

Silverlight 3 Mobile (WP7) - PathGeometry issue, please help!

开发者 https://www.devze.com 2023-01-21 11:59 出处:网络
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

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 Pa开发者_JS百科th'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;
    }


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消