2012-11-29 25 views
0

我無法播放動畫故事板。僅顯示最後一張圖片動畫。 什麼可能是錯的?不在故事板中播放動畫(使用ObjectAnimationUsingKeyFrames)

我的代碼創建動畫:

public static class AnimationHelper 
    { 
     private const string PathImageAnimation = "/LeSommet.ZooSnap.UI.WindowsPhone;component/Resources/Images/Animation/ButtonState{0}.png"; 

     public static void StartAnimation(UIElement target) 
     { 
      Storyboard storyboard = new Storyboard(); 

      ObjectAnimationUsingKeyFrames objectAnimation = new ObjectAnimationUsingKeyFrames(); 
      objectAnimation.AutoReverse = false; 
      objectAnimation.SpeedRatio = 2; 
      Storyboard.SetTargetProperty(objectAnimation, new PropertyPath("Source")); 
      Storyboard.SetTarget(objectAnimation, target); 

      for (int i = 1; i <= 4; i++) 
      { 
       DiscreteObjectKeyFrame discreteObject = new DiscreteObjectKeyFrame() 
       { 
        KeyTime = TimeSpan.FromMilliseconds(1000), 
        Value = new BitmapImage(new Uri(string.Format(PathImageAnimation, i), UriKind.Relative)) 
       }; 
       objectAnimation.KeyFrames.Add(discreteObject); 
      } 
      storyboard.Children.Add(objectAnimation); 


      storyboard.Begin(); 
     } 
    } 

我的代碼圖片XAML:

<Image Source="/LeSommet.ZooSnap.UI.WindowsPhone;component/Resources/Images/Animation/ButtonState5.png"        
          VerticalAlignment="Center" 
          HorizontalAlignment="Center" 
          Width="110" Height="110" Stretch="Fill" 
          x:Name="imageSquareAnimation"> 

回答

2

是否所有的關鍵幀在完全相同的時間?

   KeyTime = TimeSpan.FromMilliseconds(1000), 

你可以嘗試:

   KeyTime = TimeSpan.FromMilliseconds(1000 * i), 

嘗試學習如何使用混合 - 它有一個很好的編輯器來幫助您創建動畫。