这是它的样子:http://screencast.com/t/4cd1yQJReXt
小船图像应该沿着您规划的路径移动。 它确实可以工作 - 它沿着路径移动,但它始于错误的位置。 我无法弄清楚我的动画出了什么问题,我已经多次查看了代码。 应用程序的XAML非常简单,所有元素都包含在
Canvas Name ="Canvas1" Background ="Black"
这个画布是Window的子元素。
下面是执行动画的代码。 我很确定我提供给它的线条是正确的。 只是它们的参考点有些错乱。 它应该是Canvas1,但它不是。
这个画布是Window的子元素。
下面是执行动画的代码。 我很确定我提供给它的线条是正确的。 只是它们的参考点有些错乱。 它应该是Canvas1,但它不是。
NameScope.SetNameScope(this, new NameScope());
MatrixTransform buttonMatrixTransform = new MatrixTransform();
ship1.RenderTransform = buttonMatrixTransform;
this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform);
PathGeometry animationPath = new PathGeometry();
PathFigure pFigure = new PathFigure();
pFigure.StartPoint = new Point(pathnodes.ElementAt<Line>(0).X1, pathnodes.ElementAt<Line>(0).Y1);
PolyLineSegment ls = new PolyLineSegment();
foreach (Line l in pathnodes)
{
ls.Points.Add(new Point(l.X1, l.Y1));
ls.Points.Add(new Point(l.X2, l.Y2));
}
pFigure.Segments.Add(ls);
animationPath.Figures.Add(pFigure);
animationPath.Freeze();
MatrixAnimationUsingPath matrixAnimation =
new MatrixAnimationUsingPath();
matrixAnimation.IsOffsetCumulative = false;
matrixAnimation.PathGeometry = animationPath;
matrixAnimation.Duration = TimeSpan.FromSeconds(5);
matrixAnimation.DoesRotateWithTangent = true;
Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform");
Storyboard.SetTargetProperty(matrixAnimation,
new PropertyPath(MatrixTransform.MatrixProperty));
Storyboard pathAnimationStoryboard = new Storyboard();
pathAnimationStoryboard.Children.Add(matrixAnimation);
pathAnimationStoryboard.Begin(this);
谢谢你!