# .NET and More > WPF, WCF, WF >  How to: Execute code when an animation is completed?

## Nikole

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:



```
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  :Smilie:

----------


## Pac_741

The workaround solution I've implemented for this type of scenario is using the Completed event from any storyboard.

Hope it helps.

----------


## Nikole

> 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?

----------


## Nikole

please help!

----------


## Pac_741

What do you want to change it for ? Perhaps what you want to do has another solution.

----------


## Nikole

> 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 :Frown:

----------


## Pac_741

Where is your storyboard allocated in ? Within the same window.xaml file ? or in a resource dictionary ?

----------


## Nikole

> 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"

----------


## 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
}

----------


## Nikole

> 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! :Alien Frog:

----------

