I have a graphic made dynamically with a polyline object. It produces something interesting but I would like to keep only the last 10 coordonates and once we have reach the 10th position, every coordinate would move to the left by X pixel and the new value will be added at the end.
In the Add function of my drawing class I tried this kind of code:
if (points.Count > 10)
{
myPolyline.Points.RemoveAt(0);
foreach(Point p in myPolyline.Points)
{
p.X = p.X - 50;//Move all coord back to have a place for the new one
}
}
That doesn't work because we cannot modify a variable of the collection in a ForEach loop. What is the best way to do this in WPF/C#?
More info
I can do it 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 a cleaner way to do it without having to create point object very time.