如何通过关键帧触发silverlight动画中的事件?

发布于 2024-09-02 11:58:45 字数 72 浏览 1 评论 0原文

当动画到达某个关键帧时,我需要调用一个方法。当动画到达某个关键帧时是否可以触发事件?如果没有,是否有更好的方法在特定时间触发事件?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2024-09-09 11:58:45

当涉及到事件时,Silverlight 的时间表非常有限。据我所知,仅支持 Completed 事件。不过,您可以做的是在单个故事板中拥有两个时间线,其中第二个时间线正在更新您可以观看的绑定属性。

也许是这样的:

<Storyboard>
    <DoubleAnimationusingKeyFrames ... />
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="TriggerEvent">
        <ObjectKeyFrame KeyTime="00:00:01" Value="True" />
    <ObjectAnimationUsingKeyFrames>
</Storyboard>

然后在控件的代码隐藏中,定义一个名为 TriggerEvent 的 Boolean 类型的依赖属性。当它变为 true 时,调用您的方法。

另一个选择,实际上可能更好,是将原始动画分成两个并行时间线,并将 Completed 事件处理程序连接到第一个时间线(您将用它来调用您的方法)然后在第二个时间轴上,使用 BeginTime 属性同步两个动画,以便第二个动画在第一个动画完成时开始。

<Storyboard>
    <!-- Timeline 1 -->
    <DoubleAnimationusingKeyFrames Completed="MyCompletedHandler" ... />
    <!-- Timeline 2 -->
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:01" ... />
</Storyboard>

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:

<Storyboard>
    <DoubleAnimationusingKeyFrames ... />
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="TriggerEvent">
        <ObjectKeyFrame KeyTime="00:00:01" Value="True" />
    <ObjectAnimationUsingKeyFrames>
</Storyboard>

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.

<Storyboard>
    <!-- Timeline 1 -->
    <DoubleAnimationusingKeyFrames Completed="MyCompletedHandler" ... />
    <!-- Timeline 2 -->
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:01" ... />
</Storyboard>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文