我已經設置了一個故事板來沿着定義的路徑創建一個橢圓,如下所示: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();
};
哪種修改導致動畫失敗? – Heinzi 2010-11-29 01:55:28
發佈你的代碼,錯誤模糊,以幫助沒有它。 – Donnie 2010-11-29 01:56:54