How to: Execute code when an animation is completed?
Hi my dear guys, i have 2 animations (zoom in and zoom out). How can i execute code only when an animation is completed?
For example:
Code:
Dim anim_SlideOut As Animation.Storyboard = Me.FindResource("SlideOut")
Dim anim_SlideIn As Animation.Storyboard = Me.FindResource("SlideIn")
anim_SlideOut.Begin() <--- start slide out animation (about 1200 ms duration)
'Now, how can i excecute this code when anim_SlideOut animation is completed?
With imgMusicCover
.Source = imgMiniCover1.Source
.Visibility = Windows.Visibility.Visible
End With
....more code here..... hide few controls and show others
anim_SlideIn.Begin() <--- when all is finished, i want to show a slide in animation.
I'm using VB, but i can transform from C#, please help me :)
Re: How to: Execute code when an animation is completed?
The workaround solution I've implemented for this type of scenario is using the Completed event from any storyboard.
Hope it helps.
Re: How to: Execute code when an animation is completed?
Quote:
Originally Posted by
Pac_741
The workaround solution I've implemented for this type of scenario is using the Completed event from any storyboard.
Hope it helps.
Thanks :wave:, For example:
<DoubleAnimation To="35" Storyboard.TargetName="windowHeading"
Storyboard.TargetProperty="FontSize" Duration="0:0:5"
Completed="FinishedAnimation" FillBehavior="Stop" />
can i change the Completed="FinishedAnimation" at runtime?
Re: How to: Execute code when an animation is completed?
Re: How to: Execute code when an animation is completed?
What do you want to change it for ? Perhaps what you want to do has another solution.
Re: How to: Execute code when an animation is completed?
Quote:
Originally Posted by
Pac_741
What do you want to change it for ? Perhaps what you want to do has another solution.
I can't compile the project with "Completed" property in XAML storyboard. I get a syntax error. "anim_SlideOut.Completed .... function does not exist"
I'm using VS2010 with .NET framework 4.0:(
Re: How to: Execute code when an animation is completed?
Where is your storyboard allocated in ? Within the same window.xaml file ? or in a resource dictionary ?
Re: How to: Execute code when an animation is completed?
Quote:
Originally Posted by
Pac_741
Where is your storyboard allocated in ? Within the same window.xaml file ? or in a resource dictionary ?
In same window. I've tried to add Completed="GoMyFunction" to xaml storyboard in "Expression Blend", and i get same error, "Project cannot be compiled, unknow Completed property"
Re: How to: Execute code when an animation is completed?
Could you show me your xaml code ? also, Have you defined GoMyFunction void in the code behind(in the .cs file)
If not add this to your .cs file :
csharp Code:
private void GoMyFunction (object sender, EventArgs e)
{
//Your Code Here
}
Re: How to: Execute code when an animation is completed?
Quote:
Originally Posted by
Pac_741
Could you show me your xaml code ? also, Have you defined GoMyFunction void in the code behind(in the .cs file)
If not add this to your .cs file :
csharp Code:
private void GoMyFunction (object sender, EventArgs e)
{
//Your Code Here
}
Yes the event is now defined. and works, thanks!:afrog: