1
我想從自定義的點列表中構建一個簡單的多邊形PathGeometry。我在msdn website上找到了下面的代碼,它看起來工作正常,對循環進行了一個簡單的修改並添加了LineSegments,但看起來像是一堆不合理的混亂,看起來是一個相對簡單的任務。有沒有更好的辦法?從沒有其他類創建噸的點列表構建PathGeometry
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10, 50);
LineSegment myLineSegment = new LineSegment();
myLineSegment.Point = new Point(200, 70);
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
我不相信有一個更好的辦法,但你可以在一個函數把它包裝(如'路徑makePath(點[ ]點)')。 – Jashaszun