我有一个画布myCanvas,我想在指定点的位置绘制多个多边形。
PointCollection polygonpoints = new PointCollection();
private void myCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//add polygon collection
Point p = e.GetPosition(MapGrid);
polygonpoints.Add(p);
}
private void myCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Polygon poly = new Polygon();
poly.Points = polygonpoints;
poly.Fill = Brushes.AliceBlue;
MapCanvas.Children.Add(poly);
polygonpoints.Clear(); // this is making clear the polygon but the pointcollection is remain
}
polygonpoints.Clear - 我打算用它来清除下一个多边形的多边形点。但这不会发生。
请提出任何建议。
答案 0 :(得分:0)
我认为问题是您传递polygonpoints
而不是poly.Points
的副本。
将多边形创建更改为
Polygon poly = new Polygon
{
Points = new PointCollection(polygonpoints),
Fill = Brushes.AliceBlue
};