【发布时间】:2009-10-19 00:01:08
【问题描述】:
我有一个 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 点(左下角和左上角)不再连接......
我知道我在这里遗漏了一些小东西,但是请,任何帮助将不胜感激
谢谢,马克
【问题讨论】: