根据评论中的要求,我解释了我最终用来制作动画的内容:
我跟进了Silverlight 中的动画多段线插值,或多或少直接使用了这段代码——“窃取”了 PointCollectionInterpolator.cs 类。
然后我有我的方法来创建我需要的多边形并准备动画:
private void CreatePolygon(TextBox txtbx, string prop, Color curcol)
{
PointCollectionInterpolator pci = new PointCollectionInterpolator();
pci.Points1 = new PointCollection() // Start Points
{
new Point(...),
new Point(...),
new Point(...),
new Point(...),
};
pci.Points2 = new PointCollection() // End Points
{
new Point(...),
new Point(...),
new Point(...),
new Point(...),
};
Polygon tmpply = new Polygon();
LayoutRoot.Children.Add(tmpply);
tmpply.Points = pci.InterpolatedPoints;
DoubleAnimation animpci = new DoubleAnimation();
animpci.Duration = someDuration;
animpci.From = 0.0;
animpci.To = 1.0;
Storyboard.SetTarget(animpci, pci);
Storyboard.SetTargetProperty(animpci, new PropertyPath("(Progress)"));
myStoryBoard.Children.Add(animpci);
}
然后在一些随机事件处理程序中,我开始动画。此外,为了可以重用该方法,我将端点集合移到了起点集合中,并用新的端点更新了插值器。(记住将进度设置为 0.0 ...)因此,每次处理程序触发时,多边形都会无缝地变形为一个新的多边形。
private void SomeEventHandler(object sender, RoutedEventArgs e)
{
PointCollectionInterpolator polygonPCI =
this.referenceToPointCollectionInterpolator;
polygonPCI.Points1 = polygonPCI.Points2;
polygonPCI.Progress = 0.0;
polygonPCI.Points2 = getNewEndPoints();
myStoryBoard.Begin();
}
回想起来,我会将名称从 Points1 和 Points2 分别更改为 StartPoints 和 EndPoints。希望这有帮助。:)