问候!
我目前正在开发一个Silverlight项目,我想设置一个简单的多边形形状(实际上是一个梯形)。具体来说,我想在一些事件发生后动态地移动四个点中的两个。我需要/想要调整大小并将其中一个平行边移动到另一个位置。
我承认我对Silverlight很新,并且没有找到可以告诉我它甚至可能的来源,更不用说它是如何完成的了。
我之前使用过动画,所以故事板和动画的一般概念对我来说并不陌生。但是如何在动画中移动多边形的点?是否存在具有类似光学效应的替代方案(例如,为路径设置动画)? 是否有我可以使用的PropertyPath,类似于
P3AnimBack.SetValue(Storyboard.TargetPropertyProperty,
new PropertyPath("(Path.Data).
(PathGeometry.Figures)[0].(PathFigure.Segments)[0].
(BezierSegment.Point3)"));
,如Point Animation in Silverlight 3 tutorial?
中所示提前谢谢大家。 :)
答案 0 :(得分:4)
我一般都不了解Silverlight或.NET中的动画,但是Charles Petzold做了类似的事情:
答案 1 :(得分:1)
根据评论中的要求,我解释了我最终用来制作动画的内容:
我接着Animated Polyline Interpolations in 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 resp。 希望这有帮助。 :)