简体   繁体   English

Silverlight 3 Mobile(WP7)-PathGeometry问题,请帮忙!

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

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)? 在Silverlight 3 for Mobile中,如何获得路径的图形点,以便最终获得其点(X,Y坐标)? 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? 从我一直在阅读的内容来看,听起来PathPathometry的树结构没有存储在Mobile的Silverlight 3中(我正在为WP7进行此操作)...还有其他解决方法吗? All I want is the Points collection of the Path. 我想要的只是路径的Points集合。 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. 下面是我编写的用于解析路径的线段以获取点的代码,但是,Figures集合始终为空,因此我什至无法获得线段。 I've also tried using XamlReader.load to read in the Path XAML, but that has the same results, an empty Figures collection. 我也尝试过使用XamlReader.load读取Path XAML,但这具有相同的结果,即一个空的Figures集合。 I've also pasted the Path XAML below. 我还在下面粘贴了Path XAML。

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. 用于定义绝大多数路径的Mini 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. 拥有一种可以将迷你语言路径反向工程化为一组数字的方法,将是对API的一个很好的补充,但是像往常一样,需要在成本上进行权衡。

Your options are:- 您的选择是:-

  • use Xaml that includes Figures and Segment instances rather then the mini path language 使用包含Figures和Segment实例的Xaml,而不是mini path语言
  • use XmlReader or XDocument to load the Xaml containing paths, find the path of interest, parse the mini language yourself. 使用XmlReader或XDocument加载包含路径的Xaml,找到感兴趣的路径,然后自己解析迷你语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM