我有一个WPF应用程序,我需要在运行时以编程方式进行操作。
我想要做的是拥有一个包含4个线段的路径,如下所示:
Canvas.Left="324"
Canvas.Top="247">
<Path.Data>
<PathGeometry>
<PathFigure IsClosed="True">
<LineSegment Point="0.5,0.5" />
<LineSegment Point="355.5,0.5" />
<LineSegment Point="355.5,229.5" />
<LineSegment Point="0.5,229.5" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
现在,在我的c#代码中,我可以这样做:
PathFigureCollection figures = (ThePath.Data as PathGeometry).Figures;
Console.WriteLine("number of segments: " + figures[0].Segments.Count);
LineSegment topLeft = figures[0].Segments[0] as LineSegment;
LineSegment topRight = figures[0].Segments[1] as LineSegment;
LineSegment bottomRight = figures[0].Segments[2] as LineSegment;
LineSegment bottomLeft = figures[0].Segments[3] as LineSegment;
topLeft.Point = new Point(topLeft.Point.X - 5, topLeft.Point.Y - 5);
topRight.Point = new Point(topRight.Point.X + 45, topRight.Point.Y - 35);
bottomRight.Point = new Point(bottomRight.Point.X, bottomRight.Point.Y + 35);
bottomLeft.Point = new Point(bottomLeft.Point.X + 5, bottomLeft.Point.Y - 15);
但问题是,当我更改topLeft LineSegment时,“似乎”将一个点添加到段列表中,即两个LAST点(左下角和左上角)不再加入......
我知道我在这里缺少一些小东西,但是,请,任何帮助将不胜感激
谢谢,Mark
答案 0 :(得分:0)
没关系我想通了,我只需要在PathFigure上设置StartPoint,然后改变那个点以及我删除第一个的线段(考虑到我添加了StartPoint)。
感谢。