2013-12-10 28 views
0

我想製作一個動畫,其中特定網格的所有元素都應該振動。在Windows 8中通過C#動畫地鐵

所以我想這代碼..

Storyboard hintstoryboard = new Storyboard(); 

for (int i = 3; i < gridpieces.Children.Count; i++) 
{ 
    DoubleAnimationUsingKeyFrames doubleanimation = new DoubleAnimationUsingKeyFrames(); 
    Storyboard.SetTargetName(doubleanimation, ((Image)gridpieces.Children[i]).Name); 
    Storyboard.SetTargetProperty(doubleanimation, "(UIElement.Projection).(PlaneProjection.RotationZ)"); 

    EasingDoubleKeyFrame frame = new EasingDoubleKeyFrame(); 
    frame.KeyTime = TimeSpan.FromSeconds(0.1); 
    frame.Value = -5; 

    EasingDoubleKeyFrame frame1 = new EasingDoubleKeyFrame(); 
    frame1.KeyTime = TimeSpan.FromSeconds(0.2); 
    frame1.Value = 0; 

    EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame(); 
    frame2.KeyTime = TimeSpan.FromSeconds(0.3); 
    frame2.Value = 5; 

    EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame(); 
    frame3.KeyTime = TimeSpan.FromSeconds(0.4); 
    frame3.Value = 0; 

    doubleanimation.KeyFrames.Add(frame); 
    doubleanimation.KeyFrames.Add(frame1); 
    doubleanimation.KeyFrames.Add(frame2); 
    doubleanimation.KeyFrames.Add(frame3); 

    hintstoryboard.Children.Add(doubleanimation); 
} 

hintstoryboard.Begin(); 

,但它給該目標的名字沒有找到,但我的網格有相同的名稱相同的圖像異常...我已經通過代碼電網只...

任何幫助將不勝感激。

+0

嗨桑迪普,你能添加包含你正在試圖建立動畫的元素的XAML的片段? –

回答

0

我不認爲你可以在XAML之外使用SetTargetName。在後面的代碼就應該更換此:

Storyboard.SetTargetName(doubleanimation, ((Image)gridpieces.Children[i]).Name); 

與此

Storyboard.SetTarget(doubleanimation, (Image)gridpieces.Children[i]);