Animation: Timer vs Idle

2019-07-07 14:07发布

There is a similar thread else where, but it focues on gameprogramming which I find a little different to regular gui applications with some 'extra sugar'.

What would be the right approach for driving small gui-animations (like expanding/collapsing panels, glowing buttons etc)?

Would it be best to setup a timer to fire at regular intervals, or would it be better to use the idle-event?

How does WPF drive its animations?

I know there are a lot of opinions on whats best out there, so lets collect them all :-)

UPDATE: Ok. I think this came out a little unclear. I'm not using WPF, and I'm not interested in how you trigger an animation in WPF. What I'm after, is a discussion about why a time is better or worse then using an onidle event to drive the animation. Not start it, drive it.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-07 14:30

How you drive your animation should be based on your processing priorities.

If you use a timer, you will get called more consistently. This can put you in competition with more important processes for processing power. Driving by OnIdle allows other processes to take charge, but it also means that the animation could get starved.

The correct choice depends your specific priorities.

I'm not sure how WPF handles this, but it would be important to base the animation on the absolute start time rather than incrementing the animation on each call because the animation may not get called at regular intervals.

查看更多
再贱就再见
3楼-- · 2019-07-07 14:45

Maybe I'm getting it wrong but why do you need timer/idle-event if WPF supports animations natively? You may want to take a look at the Animation Overview article at MSDN: http://msdn.microsoft.com/en-us/library/ms752312.aspx

查看更多
登录 后发表回答