私は2つのオブジェクト間に曲線のパスを描画するプロジェクトに取り組んでいます。現在、ベジェ曲線とアニメーションを使って遊ぶためのテストコードをいくつか書いています。最初のテストでは、原点オブジェクト(矩形)から目的オブジェクト(別の矩形)まで直線で、端点(Point3)を移動するだけです。実際の行を設定するコードを次に示します。WPFアニメーション - ベジエ曲線点のアニメーション
connector = new Path();
connector.Stroke = Brushes.Red;
connector.StrokeThickness = 3;
PathGeometry connectorGeometry = new PathGeometry();
PathFigure connectorPoints = new PathFigure();
connectorCurve = new BezierSegment();
connectorPoints.StartPoint = new Point((double)_rect1.GetValue(Canvas.LeftProperty) + _rect1.Width/2,
(double)_rect1.GetValue(Canvas.TopProperty) + _rect1.Height/2);
connectorCurve.Point1 = connectorPoints.StartPoint;
connectorCurve.Point2 = connectorPoints.StartPoint;
connectorCurve.Point3 = connectorPoints.StartPoint;
connectorPoints.Segments.Add(connectorCurve);
connectorGeometry.Figures.Add(connectorPoints);
connector.Data = connectorGeometry;
MainCanvas.Children.Add(connector);
[OK]をクリックします。
PointAnimation pointAnim = new PointAnimation();
pointAnim.From = connectorCurve.Point3;
pointAnim.To = new Point((double)_rect2.GetValue(Canvas.LeftProperty) + _rect2.Width/2,
(double)_rect2.GetValue(Canvas.TopProperty) + _rect2.Height/2);
pointAnim.Duration = new Duration(TimeSpan.FromSeconds(5));
board.Children.Add(pointAnim);
作品を美しく:今、(エンドポイントで2つのオブジェクトを)_rect2する_rect1行くから、その行をアニメーション化することができます。しかし、私がストーリーボードでそれをしようとすると、何も得られません。ストーリーボードのコードは次のとおりです。
Storyboard board = new Storyboard();
PointAnimation pointAnim = new PointAnimation();
pointAnim.From = connectorCurve.Point3;
pointAnim.To = new Point((double)_rect2.GetValue(Canvas.LeftProperty) + _rect2.Width/2,
(double)_rect2.GetValue(Canvas.TopProperty) + _rect2.Height/2);
pointAnim.Duration = new Duration(TimeSpan.FromSeconds(5));
Storyboard.SetTarget(pointAnim, connectorCurve);
Storyboard.SetTargetProperty(pointAnim, new PropertyPath(BezierSegment.Point3Property));
board.Children.Add(pointAnim);
board.Begin();
何も動きません。私はSetTargetまたはSetTargetPropertyに何を与えているのかに問題があると思っていますが、それを理解できないようです。誰もWPFのライン/ベジエポイントをアニメーション化する経験がありますか?
私はあなたの問題を解決するとは思えませんが、あなたはこの記事のインスピレーションを見つけることができます:http://www.japf.fr/?p=227 –