【问题标题】:DoubleAnimation - On start event?DoubleAnimation - 开始事件?
【发布时间】:2012-02-20 01:23:27
【问题描述】:

我定义了一个故事板:

    <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>

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

【问题讨论】:

    标签: wpf storyboard


    【解决方案1】:

    没有 Started 事件,但您可以处理 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
    

    动画运行时。

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      相关资源
      最近更新 更多