2012-02-06 109 views
0

這是我的全部代碼異常在故事板動畫在WPF

namespace WpfApplication71 

{ 

    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 

    public partial class MainWindow : Window 
    { 
     Frame objframe; 
     TransformGroup trGrp; 
     TranslateTransform trTns; 
     ScaleTransform trScl; 

     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      objframe = new Frame(); 
      objframe.Background = Brushes.Blue; 
      trTns = new TranslateTransform(); 
      trScl = new ScaleTransform(); 
      trGrp = new TransformGroup(); 
      trGrp.Children.Add(trTns); 
      trGrp.Children.Add(trScl); 
      objframe.RenderTransform = trGrp; 
      objframe.Loaded += new RoutedEventHandler(objframe_Loaded); 
      mygrid.Children.Add(objframe); 
     } 

     void objframe_Loaded(object sender, RoutedEventArgs e) 
     { 
      var sb1 = new Storyboard(); 
      var da1 = new DoubleAnimationUsingKeyFrames(); 
      da1.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 0 }); 
      da1.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(20)), Value = 1, KeySpline = new KeySpline(0, 0, 0.4, 0.969) }); 
      da1.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(25)), Value = 1, KeySpline = new KeySpline(0, 0, 0.4, 0.969) }); 
      Storyboard.SetTargetProperty(objframe, new PropertyPath("(UIElement.Opacity)")); 
      Storyboard.SetTarget(da1, objframe); 
      sb1.Children.Add(da1); 
      var da3 = new DoubleAnimationUsingKeyFrames(); 
      da3.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 1 }); 
      da3.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(15)), Value = 0.8, KeySpline = new KeySpline(0, 0, 0.4, 0.969) }); 
      da3.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(15)), Value = 1 }); 
      da3.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(25)), Value = 1 }); 
      Storyboard.SetTargetProperty(da3, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)")); 
      Storyboard.SetTarget(da3, objframe); 
      sb1.Children.Add(da3); 

      var da5 = new DoubleAnimationUsingKeyFrames(); 
      da5.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 1 }); 
      da5.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(15)), Value = 0.8, KeySpline = new KeySpline(0, 0, 0.4, 0.969) }); 
      da5.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(15)), Value = 1 }); 
      da5.KeyFrames.Add(new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(25)), Value = 1 }); 

      Storyboard.SetTargetProperty(da5, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)")); 
      Storyboard.SetTarget(da5, objframe); 

      sb1.Children.Add(da5); 
      sb1.Begin(); 
     } 
    } 
} 

當我點擊按鈕,異常發生這種情況:

Must specify TargetProperty for 'System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames'. 

我怎樣才能解決這個問題?

+0

修復你的格式,如果你想讓人們閱讀你的代碼...(我不是指缺少[4-space indendation](http://stackoverflow.com/editing-help),我的意思是新的-lines) – 2012-02-06 16:25:37

回答