Reputation: 516
I am working on a Windows Phone 8 app. I am using a Storyboard to animate a series of images. It is working fine, but I want to call a particular method one second before the animation completes. I am using this code: Is there a way to do what I want?
var storyboard12 = new Storyboard
{
// RepeatBehavior = RepeatBehavior.Forever
};
var animation = new ObjectAnimationUsingKeyFrames();
Storyboard.SetTarget(animation, animationImage);
Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));
storyboard12.Children.Add(animation);
for (int i = 1; i <=16; i++)
{
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300*i)),
Value = String.Format("/Images+Audio/images/animation images/2_Driving-a-car/Drive_background3 ({0}).png", i)
};
animation.KeyFrames.Add(keyframe);
}
DispatcherTimer timer11 = new DispatcherTimer();
timer11.Interval = TimeSpan.FromSeconds(4.1);
timer11.Tick += timer11_Tick;
timer11.Start();
storyboard12.Begin();
storyboard12.Completed += storyboard12_Completed;
}
void timer11_Tick(object sender, EventArgs e)
{
var timer = (DispatcherTimer)sender;
timer.Stop();
changeBackgroundImage3();
}
Upvotes: 0
Views: 1983
Reputation: 788
You can use an another Storyboard, that will change a background of your control. Such way is more appropriated by a performance reason. And DispatcherTimer Tick event won't be 100% fired after set interval, it could be fired later than 4.1, if it is important for you then it is the second reason to use a storyboard to change a background.
Upvotes: 1