2011-01-29 97 views
6

我对一个简单的PathGeometry对象有一个奇怪的错误,我似乎无法弄清楚。如果有人能向我解释为什么这不起作用,我将不胜感激。WP7 PathGeometry错误

这里是一个工作路径,绘制一个小三角的例子:

<Path Data="M 8,4 L 12,12 4,12 8,4 Z" Stroke="White" /> 

这里是一个路径的例子似乎并没有为我工作:

<Path Stroke="White"> 
    <Path.Data> 
     <PathGeometry Figures="M 8,4 L 12,12 4,12 8,4 Z" /> 
    </Path.Data> 
</Path> 

的字符串中的数据和图属性是相同的,但后面的示例导致出现异常:

无效的属性值M 8,4 L 12,12 4,12 8,4 Z为财产数字。

我最想做的事情是将PathGeometry放入ResourceDictionary中,并将其作为{StaticResource}引用,以便重新使用我的形状。

编辑:

我的解决办法的,而不是试图引用一个静态资源一的PathGeometry,以代替参考字符串资源。

<sys:String x:Key="TriangleShape">M 8,4 L 12,12 4,12 8,4 Z</sys:String> 
... 
<Path Data={StaticResource TriangleShape}" /> 

回答

4

从我可以告诉,路径标记语法,13759 Path.Data,不被支持的PathGeometry。 PathGeometry.Figures属性必须是PathFigure对象的集合。

要以这种方式指定上面的形状,你可以这样做以下:

<Path Stroke="White"> 
     <Path.Data> 
      <PathGeometry> 
       <PathGeometry.Figures> 
        <PathFigure StartPoint="8,4"> 
         <PathFigure.Segments> 
          <LineSegment Point="12,12" /> 
          <LineSegment Point="4,12" /> 
          <LineSegment Point="8,4" /> 
         </PathFigure.Segments> 
        </PathFigure> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 

免责声明:我没有我的电脑上试过这个WP7上,只在Silverlight中。

+0

这确实适用于wp7!不幸的是,这是一个可以接受的选择。万分感谢。 – 2011-01-29 18:51:38