Results 1 to 10 of 10

Thread: How to: Execute code when an animation is completed?

  1. #1

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    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

  2. #2
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  3. #3

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    Re: How to: Execute code when an animation is completed?

    Quote Originally Posted by Pac_741 View Post
    The workaround solution I've implemented for this type of scenario is using the Completed event from any storyboard.

    Hope it helps.

    Thanks , 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?
    Last edited by Nikole; Apr 2nd, 2010 at 02:08 PM.

  4. #4

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    Re: How to: Execute code when an animation is completed?

    please help!

  5. #5
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  6. #6

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    Re: How to: Execute code when an animation is completed?

    Quote Originally Posted by Pac_741 View Post
    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

  7. #7
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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 ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  8. #8

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    Re: How to: Execute code when an animation is completed?

    Quote Originally Posted by Pac_741 View Post
    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"

  9. #9
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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:
    1. private void GoMyFunction (object sender, EventArgs e)
    2. {
    3.    //Your Code Here
    4. }
    C# and WPF developer
    My Website:
    http://singlebits.com/

  10. #10

    Thread Starter
    Lively Member Nikole's Avatar
    Join Date
    Feb 2010
    Posts
    79

    Re: How to: Execute code when an animation is completed?

    Quote Originally Posted by Pac_741 View Post
    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:
    1. private void GoMyFunction (object sender, EventArgs e)
    2. {
    3.    //Your Code Here
    4. }

    Yes the event is now defined. and works, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width