2010-11-29 80 views
1

我已經設置了一個故事板來沿着定義的路徑創建一個橢圓,如下所示:http://msdn.microsoft.com/en-us/library/ms743217.aspx,根據我的需要進行一些修改。然而,當我嘗試運行我的程序,它給了我一個AnimationException:WPF路徑動畫錯誤

Cannot animate the 'Center' property on a 'System.Windows.Media.EllipseGeometry' using a 'System.Windows.Media.Animation.PointAnimationUsingPath'. For details see the inner exception.

內部異常簡單地說:Value does not fall within the expected range.。我以前從未使用過故事板,所以我不知道該怎麼做。

編輯:這是我的代碼,因爲它是。它經歷了一些變化,我還沒有拿出舊評論,所以接受原樣。

 Location current = null;// locationEnum.Current; 
     Point start = new Point(); 
     var segment = new PolyBezierSegment(); 
     foreach (var location in locations) { 
      if (current == null) { 
       current = location; 
       start = new Point(current.X, current.Y); 
      } 
      else { 
       //MessageBox.Show(location.X.ToString() + "," + location.Y.ToString()); 
       segment.Points.Add(new Point(location.X, location.Y)); 
       //current = location; 
      } 
     } 
     //MessageBox.Show(start.ToString()); 
     var ellipseGeometry = new EllipseGeometry(start, 15, 15); 
     var ellipsePath = new System.Windows.Shapes.Path { 
      Fill = new SolidColorBrush(Colors.Red), 
      Data = ellipseGeometry, 
      Margin = new Thickness(15) 
     }; 
     cnvMap.Children.Add(ellipsePath); 
     var animationPath = new PathGeometry(); 
     var figure = new PathFigure(); 
     figure.StartPoint = start; 
     figure.Segments.Add(segment); 
     animationPath.Figures.Add(figure); 
     animationPath.Freeze(); 
     var animation = new PointAnimationUsingPath { 
      PathGeometry = animationPath, 
      Duration = TimeSpan.FromSeconds(10) 
     }; 
     Storyboard.SetTarget(animation, ellipseGeometry); 
     Storyboard.SetTargetProperty(
      animation, new PropertyPath(EllipseGeometry.CenterProperty)); 
     Storyboard storyboard = new Storyboard(); 
     storyboard.Children.Add(animation); 
     ellipsePath.Loaded += (sender, e) => { 
      //MessageBox.Show("Horray"); 
      storyboard.Begin(); 
     }; 
+0

哪種修改導致動畫失敗? – Heinzi 2010-11-29 01:55:28

+0

發佈你的代碼,錯誤模糊,以幫助沒有它。 – Donnie 2010-11-29 01:56:54

回答

1

我解決不了你的問題,但我可以告訴你我會怎麼調試它:

  • 選項1:以儘可能接近的示例代碼的東西替換你的代碼已經鏈接(並且預計將工作)。然後慢慢開始應用更改,直到它不再有效。您所做的最後一項更改很可能是問題的原因。如果這沒有幫助,請在此處發佈代碼,並附上兩個有問題的代碼行版本。

  • 選項2:告訴Visual Studio來停止所有異常(菜單欄/調試/例外),並試圖抓住其中內拋出異常的時刻。檢查調用堆棧和本地變量窗口,找出,其中的值是「超出預期範圍」。