I have a graphic image made dynamically with a polyline object. It creates something interesting, but I would like to save only the last 10 coordinates, and as soon as we reach the 10th position, each coordinate will move to the left by an X-pixel, and a new value will be added at the end.
In the "Add" function of my drawing class, I tried this code:
if (points.Count > 10)
{
myPolyline.Points.RemoveAt(0);
foreach(Point p in myPolyline.Points)
{
p.X = p.X - 50;
}
}
This does not work because we cannot change the collection variable in a ForEach loop. What is the best way to do this in WPF / C #?
More details
I can do this by doing this:
for (int i = 0; i < this.myPolyline.Points.Count; i++)
{
this.myPolyline.Points[i] = new Point(this.myPolyline.Points[i].X - 50, this.myPolyline.Points[i].Y);
}
But I would like to make a cleaner way to do this without creating an instant object.