动画完成事件在完全渲染之前引发
如何强制动画在继续执行我的代码之前等待其整个渲染?
我有一个简单的动画,在相当重的网格上显示加载面板,我想这需要一些时间才能使面板呈现淡入淡出效果,不幸的是,在显示动画之前引发了完成的事件,并且代码继续运行并启动使应用程序空闲几秒钟(正确)的数据进程。这应该在面板有效呈现在屏幕上之后开始!
How can I force an animation to wait its whole rendering before to keep going with my code?
I have a simple animation with shows a loading panel on a pretty heavy grid, I guess this takes some time to make the panel rendered with a fade in effect, unluckly completed event is raised before the animation is displayed and code keep going and start a data process that idles for few seconds (correctly) the application. This should be start after the panel is effectively rendered on screen!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个动画是用
LayoutTransform
还是RenderTransform
完成的?如果
LayoutTransform
那么我认为在动画完成事件中处理相关视觉对象的LayoutUpdated
事件。因此,当视觉效果实际上在动画完成后第一次响应布局传递时,这将是您的代码开始新过程的正确位置。流程开始后,为同一视觉对象取消挂钩布局更新事件。遗憾的是,对于 RenderTransform 来说,除了
CompositionTarget.Rendering
之外,没有这样的事件。您可以尝试在动画完成事件中显式处理此事件。此外,当动画完成后处理渲染事件时,请启动进程并取消挂钩渲染事件。如果不挂起此事件,您的应用程序可能会变慢。如果您需要更多帮助,请告诉我。
Is this animation done with the
LayoutTransform
orRenderTransform
?If
LayoutTransform
then I think in the animation completed event handle theLayoutUpdated
event of the relevant visual. So probably when the visual actually first responds to the layout pass after the animation finishes, it will be the correct place for yourcode to start that new process. After the process starts unhook layoutupdated event for the same visual.Sadly for
RenderTransform
there is no such event exceptCompositionTarget.Rendering
. You can try handling this event explicitly in animation completed event. Also when rendering event is handled after the animation is completed, start your process and please unhook the rendering event. This event can make your application slow if it is left unhooked.Let me know if you need any more help.
您可以调用一个空的低优先级操作:
该操作会阻止代码执行,直到处理完优先级高于 DispatcherPriority.Background 的所有操作。因此,您可以确保您的动画代码在以更高优先级执行其他一些阻塞代码之前已得到处理(并且动画逻辑保留在调度程序队列中)。
You can invoke an empty low prioratiy action:
That blocks code execution until all actions with priority higher than
DispatcherPriority.Background
are processed. So you can ensure that your animation code has been processed before some other blocking code will be exeucted with higher priority( and the animation logic remains in the dispatcher queue).