我正在尝试弄清楚如何在Avalonia中进行动画。
我有一个由4条线段组成的路径,并且我想将每个点动画到一个新的位置。在WPF中,我是这样完成的:
public void AnimatePoints(PointCollection pts, TimeSpan timespan, bool randomized = true, Action onFinished = null)
{
Points = PointCollection.Parse(PathString);
//PathFigure needs an animation too (for the start point), otherwise the first point always stays in one place
var pfa = new PointAnimation(pts[0], timespan);
if (onFinished != null)
{
pfa.Completed += (sender, args) => onFinished();
}
PathFigure.BeginAnimation(PathFigure.StartPointProperty, pfa);
for (int i = 0; i < pts.Count; i++)
{
var pa = new PointAnimation(pts[i], timespan);
if (randomized)
{
LineSegments[i].BeginAnimation(LineSegment.PointProperty, pa);
}
else
{
LineSegments[i].BeginAnimation(LineSegment.PointProperty, pa);
}
}
}
如何在Avalonia中使用代码实现相同的效果?我已经尝试使用PathTransition,但是PathFigure和LineSegments都不能进行动画处理。