WPF and c#. Animation in c# code. I have animation of path with many points (>1000). Animation is created programatically using one storyboard and point animations with ease function. Repeat behavior is set to forever. After some time ease function turns off. I think it's some kind of optimalization. Can I turn this off so that ease function will be set also forever?
This is my mainwindow_loaded function. I have only one Grid named grid in my xaml code.
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Random r = new Random(10);
Storyboard sb = new Storyboard();
Path p = new Path
{
Width = 500,
Height = 500,
Name = "Path",
Fill = Brushes.Green,
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
Margin = new Thickness(25, 25, 0, 0),
VerticalAlignment = System.Windows.VerticalAlignment.Top
};
PathGeometry pg = new PathGeometry();
var pf = new PathFigure { StartPoint = new Point(0, 250) };
for (int i = 0; i < this.ActualWidth; i++)
{
LineSegment ls = new LineSegment { Point = new Point(i, 50) };
var pa = new PointAnimation
{
To = new Point(i, 80),
Duration = new Duration(new TimeSpan(0, 0, 0, 2)),
BeginTime = new TimeSpan(0, 0, 0, 0, i * 10), //+ r.Next(200)
AutoReverse = true,
RepeatBehavior = RepeatBehavior.Forever,
EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut }
};
Storyboard.SetTargetProperty(pa, new PropertyPath("(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[" + i + "].(LineSegment.Point)"));
Storyboard.SetTarget(pa, p);
sb.Children.Add(pa);
pf.Segments.Add(ls);
}
LineSegment endSegment = new LineSegment { Point = new Point(this.ActualWidth, 250) };
pf.Segments.Add(endSegment);
pg.Figures.Add(pf);
p.Data = pg;
grid.Children.Add(p);
sb.Begin();
}
Try to put + r.Next(200) in code so that the line will look like
BeginTime = new TimeSpan(0, 0, 0, 0, i * 10 + r.Next(200)),
And then ease function will never disappear.