3

问候!

我目前正在做一个 Silverlight 项目,我想制作一个简单的多边形形状(实际上是梯形)的动画。具体来说,我想在某些事件发生后动态移动四个点中的两个。我需要/想要调整大小并将其中一个平行边移动到另一个位置。

我承认我对 Silverlight 相当陌生,还没有找到可以告诉我它是否可能的来源,更不用说它是如何完成的了。

我以前使用过动画,所以故事板和动画的一般概念对我来说并不陌生。但是如何在动画中移动多边形的点?是否有具有类似光学效果的替代品(例如动画路径)?
是否有我可以使用的 PropertyPath,类似于

P3AnimBack.SetValue(Storyboard.TargetPropertyProperty, 
    new PropertyPath("(Path.Data).
        (PathGeometry.Figures)[0].(PathFigure.Segments)[0].
        (BezierSegment.Point3)"));

在 Silverlight 3 教程中的点动画中找到?

谢谢大家。:)

4

2 回答 2

4

我对 Silverlight 或 .NET 中的动画一无所知,但Charles Petzold做了类似的事情:

于 2009-08-18T14:09:50.960 回答
1

根据评论中的要求,我解释了我最终用来制作动画的内容:

我跟进了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。希望这有帮助。:)

于 2009-08-20T10:22:01.240 回答