如何知道合成动画 'ScalarKeyFrameAnimation'(或类似动画)何时完成

How to know when Composition animation 'ScalarKeyFrameAnimation' (or similar) finished

我需要知道像 ScalarKeyFrameAnimation 这样的 Composition 动画何时完成。这该怎么做?我拨打了如下电话:

    public void Start()
    {
        if (!IsLoaded) return;
        //SET TARGET PROPERTY - OPACITY
        TargetScalarKeyFrameAnimation.Target = "Opacity";

        //SET FROM OPACITY
        if (From < 0) this.Opacity = 0;
        else if (From > 1) this.Opacity = 1;
        else this.Opacity = From;

        //SET FINAL VALUE (OPACITY) 
        if (To < 0) TargetScalarKeyFrameAnimation.InsertKeyFrame(1f, 0);
        else if (To > 1) TargetScalarKeyFrameAnimation.InsertKeyFrame(1f, 1);
        else TargetScalarKeyFrameAnimation.InsertKeyFrame(1f, (float)To);

        //SET DURATION
        if (Duration.TotalMilliseconds > 0) TargetScalarKeyFrameAnimation.Duration = Duration;
        else TargetScalarKeyFrameAnimation.Duration = TimeSpan.FromSeconds(1);

        //SET DELAY
        if (Delay.TotalMilliseconds > 0) TargetScalarKeyFrameAnimation.DelayTime = Delay;
        else TargetScalarKeyFrameAnimation.DelayTime = TimeSpan.FromMilliseconds(0);

        //START
        this.StartAnimation(TargetScalarKeyFrameAnimation);
    }

但是如何让通知动画播放完毕呢?同步 UI 和其他动画会有很大帮助。 StoryboardAnimation 有一个活动。

How to know when Composition animation 'ScalarKeyFrameAnimation' (or similar) finished

目前,没有这样的事件可以检测合成动画完成Api。对于您的场景,您可以创建一个 timer ans set Interval same as animation duration, and call StartAnimation and timer Start at same time. Then could detect animation finished in timer Tick 事件。