1

我有以下代码:

<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);
4

1 回答 1

1

您的最后一个动画的 aDuration为 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>
于 2014-11-04T12:13:34.103 回答