如何通过关键帧触发silverlight动画中的事件?
当动画到达某个关键帧时,我需要调用一个方法。当动画到达某个关键帧时是否可以触发事件?如果没有,是否有更好的方法在特定时间触发事件?
I need to call a method when the animation gets to a certain keyframe. Is it possible to trigger an event when an animation gets to a certain keyframe? If not is there a better way of triggering an event at a certain time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当涉及到事件时,Silverlight 的时间表非常有限。据我所知,仅支持 Completed 事件。不过,您可以做的是在单个故事板中拥有两个时间线,其中第二个时间线正在更新您可以观看的绑定属性。
也许是这样的:
然后在控件的代码隐藏中,定义一个名为 TriggerEvent 的 Boolean 类型的依赖属性。当它变为 true 时,调用您的方法。
另一个选择,实际上可能更好,是将原始动画分成两个并行时间线,并将 Completed 事件处理程序连接到第一个时间线(您将用它来调用您的方法)然后在第二个时间轴上,使用 BeginTime 属性同步两个动画,以便第二个动画在第一个动画完成时开始。
Silverlight timelines are very limited when it comes to events. As far as I can tell, only the Completed event is supported. What you could do though is have two timelines inside a single storyboard where the second timeline is updating a bound property that you could watch.
Maybe something like:
Then in your code behind for the control, define a dependency property called TriggerEvent of type Boolean. When it changes to true, call your method.
Another option however, which is probably better actually, would be to split your original animation into two parallel timelines and hook up a Completed event handler to the first timeline (which you'd use to call your method) then on the second timeline, use the BeginTime property to synchronize the two animations so that the second one picks up just as the first one is completing.