2012-05-19 31 views
0

我有這樣的代碼,但我不能使用,因爲這是拋出異常,當我打電話sb.Begin():未指定Silverlight「未指定動畫目標」。

動畫目標。

public void TableCardAnimation(UserControl cardControl, double Height, double Width) 
    { 
     Storyboard sb = new Storyboard(); 
     DoubleAnimation animHeight = new DoubleAnimation(); 
     animHeight.Duration = new Duration(new TimeSpan(0, 0, 2)); 
     animHeight.From = cardControl.Height; 
     animHeight.To = Height; 
     sb.Children.Add(animHeight); 
     Storyboard.SetTarget(animHeight, cardControl); 
     Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Height)")); 


     DoubleAnimation animWidth = new DoubleAnimation(); 
     animWidth.Duration = new Duration(new TimeSpan(0, 0, 2)); 
     animWidth.From = cardControl.Width; 
     animWidth.To = Width; 
     sb.Children.Add(animWidth); 
     Storyboard.SetTarget(animWidth, cardControl); 
     Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Width)")); 

     sb.Begin(); 
    } 

在那裏我錯了嗎? :(

回答

0

顯然,這只是一個打字錯誤

在該行

Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Width)")); 

你設定的目標屬性爲animHeight次要的,但你的animWidth目標屬性並未設置你可能。想做的事:

Storyboard.SetTargetProperty(animWidth, new PropertyPath("(Width)")); 

,爲什麼你使用"(Width)"而不只是"Width"