【问题标题】:Animation not firing last part动画没有触发最后一部分
【发布时间】:2014-11-04 12:04:23
【问题描述】:

我有以下代码:

<Storyboard x:Key="CounterStoryboard" >

    <!-- Panel appear -->
    <ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
    </ObjectAnimationUsingKeyFrames>

    <!-- 3-->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel3" From="1" To="0" Duration="0:0:1" BeginTime="0:0:0">
    </DoubleAnimation>

    <!-- 2 -->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel2" From="0" To="1" Duration="0:0:0" BeginTime="0:0:1">
    </DoubleAnimation>
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel2" From="1" To="0" Duration="0:0:1" BeginTime="0:0:1">
    </DoubleAnimation>

    <!-- 1 -->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel1" From="0" To="1" Duration="0:0:0" BeginTime="0:0:2">
    </DoubleAnimation>
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel1" From="1" To="0" Duration="0:0:1" BeginTime="0:0:2">
    </DoubleAnimation>

    <!-- Panel disappear -->
    <ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{x:Static Visibility.Collapsed}"/>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

这就像一个计数器,从 3 到 1。一切正常,除了最后一部分。 Panel disappear 不工作。它应该使面板不可见,但它仍然存在......

我做错了什么?

注意:我这样称呼故事板:

sb = (Storyboard)FindResource("CounterStoryboard");
sb = sb.Clone();
sb.Completed += sb_Completed;
sb.Begin(this);

【问题讨论】:

    标签: wpf xaml animation wpf-animation


    【解决方案1】:

    您上一个动画的 Duration 为 0:0:0,但您将 KeyTime 设置为 0:0:3,这超出了持续时间。您可以将KeyTime 更改为0:0:0 并将BeginTime 设置为0:0:3

    <ObjectAnimationUsingKeyFrames Duration="0:0:0" BeginTime="0:0:3" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
    </ObjectAnimationUsingKeyFrames>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多