2 つのオブジェクト間に曲線のパスを描画するプロジェクトに取り組んでいます。現在、ベジェ曲線とアニメーションをいじるテスト コードを書いています。最初のテストは、終点 (Point3) を元のオブジェクト (四角形) から目的のオブジェクト (別の四角形) に直線で移動するだけです。実際の行を設定するコードは次のとおりです。
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、これで線が点に折りたたまれました。次に、_rect1 から _rect2 (端点にある 2 つのオブジェクト) に移動して、その行をアニメーション化します。
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);
美しく動作します。しかし、ストーリーボードでやろうとすると、何も得られません。ストーリーボード化されたコードは次のとおりです。
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でライン/ベジェポイントをアニメーション化した経験のある人はいますか?