使用路径标记语法,您可以轻松地创建具有自定义形状(如钻石)的Path:
<Path Data="M 0,5 L 5,0 L 10,5 L 5,10 Z" />是否可以在PathGeometry中使用这个语法(上面的链接是http://msdn.microsoft.com/en-us/library/System.Windows.Media.PathGeometry_properties(v=vs.95%29.aspx)?(针对WPF而不是Silverlight),我尝试使用PathGeometry.Figures。
<local:SomeControl>
<local:SomeControl.Geometry>
<PathGeometry Figures="M 0,5 L 5,0 L 10,5 L 5,10 Z" />
</local:SomeControl.Geometry>
</local:SomeControl>但这会引发一个XamlParseException
无法从文本“M 0,5 L 5,0 L10,5 L 5,10 Z”中创建“PathGeometry.Figures”
我真的需要使用下面的扩展表单,还是有什么方法可以使用短字符串?
<PathGeometry>
<PathFigure StartPoint="0,5" IsClosed="True" IsFilled="True">
<LineSegment Point="5,0" />
<LineSegment Point="10,5" />
<LineSegment Point="5,10" />
</PathFigure>
</PathGeometry>发布于 2014-08-26 20:23:45
我刚刚注意到method有一个ConvertToPathGeometry助手方法。因此,使用以下方法很容易地创建一个IValueConverter:
return GeometryHelper.ConvertToPathGeometry((string)parameter);然后,可以将几何设置为如下所示的PathGeometry实例:
<local:SomeControl Geometry="{Binding ConverterParameter='M 0,5 L 5,0 L 10,5 L 5,10 Z',
Converter={StaticResource PathGeometryConverter}}"
/>https://stackoverflow.com/questions/25023902
复制相似问题