Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Animation AutoReverse=false,但仍会执行此操作,并且从错误的起点开始_C#_.net_Wpf_Animation_.net 4.5 - Fatal编程技术网

C# Animation AutoReverse=false,但仍会执行此操作,并且从错误的起点开始

C# Animation AutoReverse=false,但仍会执行此操作,并且从错误的起点开始,c#,.net,wpf,animation,.net-4.5,C#,.net,Wpf,Animation,.net 4.5,我试图从画布的右下角到左上角获得一个图像,永远重复这个行为。图像不应从左上角到右上角进行反向动画。我是动画新手,所以我用了 此时,我的图像正在从左上角移动到右下角并返回。我尝试更改画布中图像的开始位置,结果,动画使用此位置作为新的起点。我还尝试使用负值,使图像移动到相反的方向。减少片段中的点数量可以缩短动画路径,但没有其他效果。我还将AutoReverse设置为false,而不改变动画行为 我的想法是, -segment类正在用点构建一个圆,但是要使用哪个其他类呢? -开始位置必须更改,但是如何

我试图从画布的右下角到左上角获得一个图像,永远重复这个行为。图像不应从左上角到右上角进行反向动画。我是动画新手,所以我用了

此时,我的图像正在从左上角移动到右下角并返回。我尝试更改画布中图像的开始位置,结果,动画使用此位置作为新的起点。我还尝试使用负值,使图像移动到相反的方向。减少片段中的点数量可以缩短动画路径,但没有其他效果。我还将AutoReverse设置为false,而不改变动画行为

我的想法是, -segment类正在用点构建一个圆,但是要使用哪个其他类呢? -开始位置必须更改,但是如何使对象在屏幕上向上移动而不是向下移动

我的代码

Storyboard animationSB = new Storyboard();

//Image book = createImage(model.keywordCollection[0].cover.small);
Image rope1 = createImage("pack://application:,,,/GUI;component/Resources/rope_trans.png");
rope1.Height = 360.0;
rope1.Width = 185.0;

//Transform to move the book image
TranslateTransform aniRope1 = new TranslateTransform();
this.RegisterName("AnimatedRope1", aniRope1);
rope1.RenderTransform = aniRope1;
Canvas.SetLeft(rope1, 258.659);
Canvas.SetTop(rope1, 583.212);
LeftRope.Children.Add(rope1);


//Anitmation path
PathGeometry animationPath1 = new PathGeometry();
PathFigure pathFigure1 = new PathFigure();
PolyLineSegment lineSegments1 = new PolyLineSegment();
lineSegments1.Points.Add(new Point(LeftRope.ActualWidth, LeftRope.ActualHeight));
lineSegments1.Points.Add(new Point(258.659, 583.212));
lineSegments1.Points.Add(new Point(120.596, 272.665));
lineSegments1.Points.Add(new Point(0, 0));
pathFigure1.Segments.Add(lineSegments1);
animationPath1.Figures.Add(pathFigure1);
animationPath1.Freeze();

//Animate transform to move image along the path on the x-axis
DoubleAnimationUsingPath translateXAnimation1 = new DoubleAnimationUsingPath();
translateXAnimation1.PathGeometry = animationPath1;
translateXAnimation1.Duration = TimeSpan.FromSeconds(6);
translateXAnimation1.Source = PathAnimationSource.X;
translateXAnimation1.AutoReverse = false;

Storyboard.SetTargetName(translateXAnimation1, "AnimatedRope1");
Storyboard.SetTargetProperty(translateXAnimation1, new PropertyPath(TranslateTransform.XProperty));

//Animate transform to move image along the path on the y-axis
DoubleAnimationUsingPath translateYAnimation1 = new DoubleAnimationUsingPath();
translateYAnimation1.PathGeometry = animationPath1;
translateYAnimation1.Duration = TimeSpan.FromSeconds(6);
translateYAnimation1.Source = PathAnimationSource.Y;
translateYAnimation1.AutoReverse = false;

Storyboard.SetTargetName(translateYAnimation1, "AnimatedRope1");
Storyboard.SetTargetProperty(translateYAnimation1, new PropertyPath(TranslateTransform.YProperty));

//Create Storyboard containing and applying the animation

//animationSB.RepeatBehavior = RepeatBehavior.Forever;
animationSB.Children.Add(translateXAnimation1);
animationSB.Children.Add(translateYAnimation1);

animationSB.AutoReverse = false;
故事板是用另一种方法启动的


我正在windows 8.1N上开发带有.Net 4.5.1c的桌面应用程序。

您应该替换以下行:

lineSegments1.Points.Add(new Point(LeftRope.ActualWidth, LeftRope.ActualHeight));

结果表明,如果不为PathFigure指定起始点,它会自动关闭该地物,即连接点集合中的最后一个点和第一个点

pathFigure1.StartPoint = new Point(LeftRope.ActualWidth, LeftRope.ActualHeight);