简体   繁体   中英

WPF: How to call a method at a specific point in time while an animation is running

My problem is the following:

I've got an animation which makes a panel slide until it disappears (I animate its margin property). As soon as the animation ends, I want the panel to go back where it was at the start. So I set the autoreverse property to true, animation duration doubles automaticly, and everithing runs fine. Problem is I'm still missing something fundamental in my program: when the animation has run midway, that is when the panel disappears, I have to do some processing, calling a method, which makes the panel content change its UI. So, is there a way to do this?

Thanks

As @deafjeff suggests, you could make 2 animation instead of using autoreverse. Register a handler for the Completed event for the first animation. Do the UI changes and start 2nd animation in the hanlder code. Code is like followig:

private void onFirstAnimationCompleted(object sender, EventArgs e)
{
  DoUIChange();
  SecondAnimation.Start();
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM