2014-10-02 53 views
7

我是一個WPF和XAML的完全新手。可重複使用的動畫

我創建了一個簡單的淡入和淡出動畫爲一個文本框: - 我想要做的是動畫的生命週期內運行這個故事板幾次

<Storyboard x:Key="storyFadeInOutTop" Name="storyFadeInOutTop"> 
    <DoubleAnimation From="0" To="1" Duration="00:00:01" 
        Storyboard.TargetName="txtTopCredit" 
        Storyboard.TargetProperty="Opacity"> 
    </DoubleAnimation> 
    <DoubleAnimation From="10" To="0" Duration="00:00:01" BeginTime="00:00:01" 
        Storyboard.TargetName="blurTop" 
        Storyboard.TargetProperty="Radius"> 
    </DoubleAnimation> 
    <DoubleAnimation From="0" To="10" Duration="00:00:01" BeginTime="00:00:05" 
        Storyboard.TargetName="blurTop" 
        Storyboard.TargetProperty="Radius"> 
    </DoubleAnimation> 
    <DoubleAnimation From="1" To="0" Duration="00:00:01" BeginTime="00:00:06" 
        Storyboard.TargetName="txtTopCredit" 
        Storyboard.TargetProperty="Opacity"> 
    </DoubleAnimation> 
</Storyboard> 

喜歡的東西: -

<Storyboard> 
    <!-- (Run my fade-in-fade out with BeginTime of 00:00:00) --> 
    <StringAnimationUsingKeyFrames Duration="00:00:01" BeginTime="00:00:07" 
      Storyboard.TargetName="txtTopCredit" 
      Storyboard.TargetProperty="Text"> 
      <DiscreteStringKeyFrame Value="Game design and concept by" KeyTime="0:0:1" /> 
    </StringAnimationUsingKeyFrames> 
    <!-- (Run my fade-in-fade out again with BeginTime of 00:00:07) --> 
    <StringAnimationUsingKeyFrames Duration="00:00:01" BeginTime="00:00:07" 
      Storyboard.TargetName="txtTopCredit" 
      Storyboard.TargetProperty="Text"> 
      <DiscreteStringKeyFrame Value="Look Ive changed to another credit" KeyTime="0:0:1" /> 
    </StringAnimationUsingKeyFrames> 
    <!-- (etc etc) --> 
</Storyboard> 

我希望你明白我想要做的要點。我知道我可以將故事板中的代碼添加到上面的每個部分,但這會非常乏味。有沒有一個優雅的方式來做到這一點?

+0

注意:O.K.所以我做了一些挖掘和使用代碼來啓動和停止故事板,以及事件處理程序來控制它們運行時的順序。這將是很高興知道是否有一種方法可以在純XAML中執行此操作。 – 2014-10-02 14:18:33

+2

我認爲你最好用代碼管理這些動畫(不幸的是)。 – 2014-12-16 09:06:19

回答

1

您應該能夠設置在故事板(inherited from Timeline)

<Storyboard x:Key="storyFadeInOutTop" Name="storyFadeInOutTop" RepeatBehavior="Forever"> 
    <DoubleAnimation From="0" To="1" Duration="00:00:01" 
        Storyboard.TargetName="txtTopCredit" 
        Storyboard.TargetProperty="Opacity"> 
    </DoubleAnimation> 
    <DoubleAnimation From="10" To="0" Duration="00:00:01" BeginTime="00:00:01" 
        Storyboard.TargetName="blurTop" 
        Storyboard.TargetProperty="Radius"> 
    </DoubleAnimation> 
    <DoubleAnimation From="0" To="10" Duration="00:00:01" BeginTime="00:00:05" 
        Storyboard.TargetName="blurTop" 
        Storyboard.TargetProperty="Radius"> 
    </DoubleAnimation> 
    <DoubleAnimation From="1" To="0" Duration="00:00:01" BeginTime="00:00:06" 
        Storyboard.TargetName="txtTopCredit" 
        Storyboard.TargetProperty="Opacity"> 
    </DoubleAnimation> 
</Storyboard> 

RepeatBehavior也可以設置爲正整數RepeatBehavior財產。