I am trying to make a video animation from WPF controls. So far i draw a line to a Canvas, change the position by 1 pixel, save the canvas as an image and do the same again until the animation is completed. Now there is the Storyboard functionality which lets me create an animation like this:
var fade = new DoubleAnimation()
{
From = 0,
To = 1,
Duration = TimeSpan.FromSeconds(5),
};
Storyboard.SetTarget(fade, line);
Storyboard.SetTargetProperty(fade, new PropertyPath(Line.OpacityProperty));
var sb = new Storyboard();
sb.Children.Add(fade);
sb.Begin();
That simply applies a fade-in animation on a line.
The Question is: can i stop the animation every step, do something and then continue? i did not find an appropiate event to do that. What i tried was to override the canvas, like this:
class VideoableCanvas: Canvas
{
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
Debug.WriteLine("Canvas OnRender");
}
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
{
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
Debug.WriteLine("Canvas OnVisualChildrenChanged");
}
}
And used like this:
<local:VideoableCanvas x:Name="canvas">
<Line X1="10" X2="100" Y1="20" Y2="100" StrokeThickness="4" Stroke="Black" Name="line" />
</local:VideoableCanvas>
But those Events to only fire once. The Storyboard itself also does not seem to have any event halting the animation every frame.
How do i stop an animation every frame, or possibly have a "OnReDraw" Event on a canvas or a Window?