WPF Animation Duration

折月煮酒 提交于 2020-01-02 06:51:26

问题


I have a storyboard like the following

Duration="0:0:1" Completed="DeviceExplorer_Completed">

The animation for some reason does not appear to be working linearly. If I change the duration to something like Duration="0:0:0.8"

and assign the stroyboard to a MouseEnter event of a button, the animation moves but does not complete for some reason, I move my mouse over the button a few times before it enetually completes...

Any ideas why?


回答1:


I had an issue with something like this when I was creating the storyboard and animations dynamically. What helped me was to ensure that the duration was set on the individual animations. You might try putting a button on your screen and using that to fire the storyboard... placing a breakpoint there would let you ensure that the animations had the same duration as the storyboard.

After finding the workaround, I haven't had the time to fully debug the issue but I suspect it had to do with the order in which I am creating the storyboard and animations. In my situation, the storyboard is very dynamic so adjusting the duration on a few extra objects is the least of my concerns.




回答2:


You have to set the duration on the animation and not the storyboard. The animation will default to a duration of 1 second if not set and the storyboard is ending in less time than that so the animation gets cut short by whatever length of time is the difference. When you put the duration on the animation it should work fine.



来源:https://stackoverflow.com/questions/2431004/wpf-animation-duration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!