8

从.net代码停止和重新启动情节提要的正确方法是什么?

我正在努力 ...

myStory.Stop(this);

期望随后调用 .Begin(this); 将从零处的时间线重新开始,但故事板会在它停止的地方重新开始。

我试过了

.Remove(this);

我试过了

.Seek(TimeSpan.Zero); 

这也没有用。

更多细节......这是我的故事板示例。

<Storyboard x:Key="overlay">
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textone" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="0"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="texttwo" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="0"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

因此 textone 中的文本运行,如果您关闭屏幕并快速返回屏幕,texttwo 实际上会在新启动的故事板上播放。所以最初的(从第一个屏幕)故事板仍然在播放,即使我已经删除并停止了它。

4

5 回答 5

11

使用 Storyboard.Seek(TimeSpan.Zero) 怎么样?与在 Stream 中搜索类似,这应该会让您回到动画的开头。

我评论说您还应该确保 IsControllable 属性设置为 true。记住这一点!

Storyboard.Seek 方法

于 2009-05-07T20:57:17.887 回答
3

您需要在调用 myStory.Begin(this) 之前执行 myStory.Remove(this) 以使其从头开始。这是因为调用 Storyboard::Stop 只会停止动画时钟,但会保持原样。随后对 Begin 的调用将仅充当简历。我同意这有点违反直觉,但是如果您阅读文档ClockController::Stop,您将在备注中看到以下内容:

此方法将目标时钟的 CurrentState 更改为 Stopped。

可以使用 Begin、Seek 或 SeekAlignedToLastTick 方法重新启动已停止的时钟。

于 2009-05-07T01:06:40.150 回答
0

对不起斯科特,我没注意。您是否尝试在情节提要上设置 FillBehavior。将 FillBehavior 设置为 Stop 会重置动画。不知道为什么停止不这样做......

于 2009-05-26T20:23:20.330 回答
0
<Storyboard x:Key="overlay">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textone" Storyboard.TargetProperty="(UIElement.Opacity)">
    <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="0"/>
    <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="texttwo" Storyboard.TargetProperty="(UIElement.Opacity)">
    <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="0"/>
    <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="0"/>
</DoubleAnimationUsingKeyFrames>

 using System.Windows.Media.Animation;

然后创建新的故事板

 Storyboard storyboard_name = (Storyboard)(FindResource("overlay")); 
 storyboard_name.Begin();

故事板“storyboard_name”将开始。

如果你想停止故事板。请尝试这样

storyboard_name.Stop();

如果你想删除情节提要。请尝试这样

storyboard_name.Remove();
于 2012-06-04T04:22:39.307 回答
-1

其他细节可以是:

this.MyAnimation.FillBehavior = FillBehavior.Stop;

于 2014-01-21T19:13:28.757 回答