[英]WPF Path Animation Error
我已經設置了一個情節提要板來沿定義的路徑設置橢圓動畫,如下所示: http : //msdn.microsoft.com/zh-cn/library/ms743217.aspx ,進行了一些修改以滿足我的需要。 但是,當我嘗試運行程序時,它給了我AnimationException:
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();
};
我無法解決您的問題,但是我可以告訴您如何調試它:
選項1 :用與您鏈接的示例代碼盡可能接近的代碼替換您的代碼(該代碼可以正常工作)。 然后慢慢開始應用您的更改,直到不再起作用。 您所做的最后更改很可能是造成問題的原因。 如果這樣做沒有幫助,請在此處發布代碼,以及有問題的代碼行的兩個版本。
選項2 :告訴Visual Studio停止所有異常(菜單欄/調試/異常),並嘗試捕捉引發內部異常的時刻。 檢查“調用堆棧”和“本地變量”窗口,以找出哪個值“超出預期范圍”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.