2012-05-17 185 views
0

我的代碼張貼在下面。我正在創建一個圖像,並嘗試向其添加動畫。我確信它在某一時刻起作用,我做了一個小小的改變,但是我沒有取消改變(從字面上撤消),現在它仍然失敗。我試圖在半秒內對另一張圖像進行圖像更改,然後再過半秒鐘後再更改一次。故障動畫圖像,看起來故事板不啓動

<Image Height="30" HorizontalAlignment="Left" Margin="198,90,0,0" Name="OldMan" Stretch="Fill" VerticalAlignment="Top" Width="30" Source="/TestingWpF;component/Images/Old1.png" > 
    <Image.Triggers> 
     <EventTrigger RoutedEvent="Window.Loaded"> 
      <BeginStoryboard> 
       <Storyboard > 
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OldMan" Storyboard.TargetProperty="(Image.Source)" RepeatBehavior="Forever"> 
         <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000"> 
          <DiscreteObjectKeyFrame.Value> 
           <BitmapImage UriSource="/TestingWpF;component/Images/Old1.png" /> 
          </DiscreteObjectKeyFrame.Value> 
         </DiscreteObjectKeyFrame> 
         <DiscreteObjectKeyFrame KeyTime="00:00:01.0000000"> 
          <DiscreteObjectKeyFrame.Value> 
           <BitmapImage UriSource="/TestingWpF;component/Images/Old2.png" /> 
          </DiscreteObjectKeyFrame.Value> 
         </DiscreteObjectKeyFrame> 
        </ObjectAnimationUsingKeyFrames> 
       </Storyboard> 
      </BeginStoryboard> 
     </EventTrigger> 
    </Image.Triggers> 
</Image> 

回答

1

問題是您沒有持續時間設置。你會得到第一個關鍵幀,但不是下一個。嘗試添加像Duration="00:00:01.5"ObjectAnimationUsingKeyFrames

+0

持續時間是問題的感謝。對於記錄,我將動畫從0:0:0和0:0:0.5開始更改,並將持續時間設置爲0:0:01,這實現了一個很好的平衡流動,只要它允許我將標記爲答案 –

+0

很高興幫助! – Dave