DoubleAnimation - 开始活动?

时间:2012-02-19 13:59:45

标签: wpf storyboard

我定义了故事板:

    <Grid.Resources>
        <Storyboard x:Key="MasterAnim" x:Name="MasterAnim" Duration="0:0:10" >
            <DoubleAnimation x:Name="ANIMATABLE_WidthExp"
                             Storyboard.TargetName="ANIMELEMENT_SboardRect1" 
                             Storyboard.TargetProperty="Width"
                             From="100" 
                             To="800" 
                             Duration="0:0:5" />

            <DoubleAnimation x:Name="ANIMATABLE_HeightExp"
                             Storyboard.TargetName="ANIMELEMENT_SboardRect1" 
                             Storyboard.TargetProperty="Height"
                             From="100" 
                             To="800" 
                             BeginTime="0:0:5"
                             Duration="0:0:5" />
        </Storyboard>

    </Grid.Resources>

是否有任何方法可以捕获每个双动画即将开始的时间?我需要在动画开始之前调用它所针对的元素上的方法,但我不确定最好的方法是什么。

1 个答案:

答案 0 :(得分:2)

没有已启动事件,但您可以处理DoubleAnimation上的CurrentTimeInvalidated,CurrentStateInvalidated和Completed事件。可能只需要CurrentStateInvalidated。

private void DoubleAnimationCurrentTimeInvalidated(object sender, EventArgs e)
{
    var clock = (AnimationClock) sender;

    Debug.WriteLine(string.Format("CurrentTime: state={0}, progress={1}, time={2}", clock.CurrentState, clock.CurrentProgress, clock.CurrentTime));
}

private void DoubleAnimationCurrentStateInvalidated(object sender, EventArgs e)
{
    var clock = (AnimationClock)sender;

    Debug.WriteLine(string.Format("CurrentState: state={0}", clock.CurrentState));
}

private void DoubleAnimationCompleted(object sender, EventArgs e)
{
    var clock = (AnimationClock) sender;

    Debug.WriteLine(string.Format("Completed: state={0}", clock.CurrentState));
}

忽略我们当前的时间

  CurrentState: state=Active

  CurrentState: state=Filling

  Completed: state=Filling

动画运行时。