我试图慢慢地为曲线制作动画,但我不知道如果我想让它从起点到X2,Y2点动画,我应该使用什么。
private void DrawLine(Canvas canvas, double X1, double Y1, double X2, double Y2, Brush color)
{
QuadraticBezierSegment qbs = new QuadraticBezierSegment(new Point(X2, Y1), new Point(X2, Y2), true);
PathSegmentCollection pscollection = new PathSegmentCollection();
pscollection.Add(qbs);
PathFigure pf = new PathFigure();
pf.Segments = pscollection;
pf.StartPoint = new Point(X1, Y1);
PathFigureCollection pfcollection = new PathFigureCollection();
pfcollection.Add(pf);
PathGeometry pathGeometry = new PathGeometry();
pathGeometry.Figures = pfcollection;
Path path = new Path();
path.Data = pathGeometry;
path.Stroke = color;
path.StrokeThickness = 1;
canvas.Children.Add(path);
Storyboard story = new Storyboard();
DoubleAnimation dAnim1 = new DoubleAnimation(Y1, Y2, new Duration(new TimeSpan(0, 0, 0, 0, 750)));
DoubleAnimation dAnim2 = new DoubleAnimation(X1, X2, new Duration(new TimeSpan(0, 0, 0, 0, 750)));
Storyboard.SetTargetProperty(dAnim1, new PropertyPath("???"));
Storyboard.SetTargetProperty(dAnim2, new PropertyPath("???"));
story.Children.Add(dAnim1);
story.Children.Add(dAnim2);
path.BeginStoryboard(story);
}