如何在代码中创建这样的路径?

时间:2013-12-24 13:44:43

标签: wpf

如何在代码中创建以下xaml:

  <Canvas>
         <Path Width="38" Height="9" 
Canvas.Left="-15" Canvas.Top="-1" 
Stretch="Fill" Fill="#FFF2F2F2" 
Data="F1 M 0.684,18.073 L12.790,5.968 L12.790,14.385 L54.794,14.385 L54.794,21.761 L12.790,21.761 L12.790,30.178 Z "/>
</Canvas>

2 个答案:

答案 0 :(得分:2)

根据这个答案:https://stackoverflow.com/a/2029805/1683224

你可以这样做:

var path = new Path();
path.Data = Geometry.Parse("F1 M 0.684,18.073 L12.790,5.968 L12.790,14.385 L54.794,14.385 L54.794,21.761 L12.790,21.761 L12.790,30.178 Z");

然后根据需要更改path的其他属性。

答案 1 :(得分:0)

创建Path的新实例,在Data字段中,使用Geometry类解析这些F1 M 0.684,18.073 L12.790,5.968 L12.790,14.385 L54.794,14.385 L54.794,21.761 L12.790,21.761 L12.790,30.178 Z

对于该职位,使用框架元素的SetValue方法,如path.SetValue(Canvas.LeftProperty, -15)