Click here to Skip to main content
15,075,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I would like to dynamically modify animation properties, like From, To or Duration. I managed to do this. However, the current solution restarts the animation from the beginning, which I do not like.
Storyboard story = RectanglesControl.FindResource("RectanglesAnimationStoryboard") as Storyboard;
TimeSpan time = story.GetCurrentTime();
story.Stop();
ThicknessAnimation anim = (ThicknessAnimation)story.Children[0];
Thickness zero = new Thickness(0, 0, 0, 0);
Thickness off = new Thickness(0, -x, 0, 0);
    anim.From = zero;
    anim.To = off;
anim.Duration = new Duration(TimeSpan.FromMilliseconds(mt));
story.Begin(this, true);
story.Seek(time);

XAML:
HTML
<Storyboard x:Key="RectanglesAnimationStoryboard">
    <ThicknessAnimation Storyboard.TargetProperty="Margin"
                        Storyboard.TargetName="RectanglesControl" From="0,-40,0,0" 
                        To="0,0,0,0" RepeatBehavior="Forever" Duration="0:0:1" />
</Storyboard>

My unsuccessful trials are in italic.

How to resume a storyboard to a previous state after making the above modifications?
Posted
Updated 30-Jan-12 12:17pm
v4

1 solution

Is there an event on the storyboard when it starts ? I'd do your seek inside that event, because with a lot of WPF stuff, it needs to be running before you can set it's position. I am sure there's a 'storyboard position changed' type event, at least.
   
Comments
Lutosław 2-Feb-12 19:09pm
   
No success. Tried to code
void RectanglesAnimationStoryboard_CurrentTimeInvalidated(object sender, EventArgs e)
{
if (seek != null)
{
//var clockGroup = sender as ClockGroup;
//clockGroup.Timeline.???
RectanglesAnimationStoryboard.Seek(seek.Value);
seek = null;
}
}
It changed /something/ -- it does seek but it still is not fluent. What is interesting -- it is more accurate at the beginning, but if the changes are applied many times (user can change a speed of an animation) and an uptime is bigger, then the accuracy drops.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900