2

RenderTransformプロパティをアニメーション化する必要があるCanvasがあります。開始マトリックスと終了マトリックスは任意であるため、XAMLでストーリーボードを事前に作成することはできません。そのため、コードで作成しようとしています。これを行う方法の例は見つかりません。以下が私の最善の試みです。これは機能しません(コンパイルして実行しますが、rendertransformは変更されません)。

これをどのように行うべきかについての提案はありますか?

MatrixAnimationUsingKeyFrames anim = new MatrixAnimationUsingKeyFrames();
MatrixKeyFrameCollection keyframes = new MatrixKeyFrameCollection();
DiscreteMatrixKeyFrame start = new DiscreteMatrixKeyFrame(fromMatrix, KeyTime.FromPercent(0));
DiscreteMatrixKeyFrame end = new DiscreteMatrixKeyFrame(toMatrix, KeyTime.FromPercent(1));

keyframes.Add(start);
keyframes.Add(end);
anim.KeyFrames = keyframes;

Storyboard.SetTarget(anim, World.RenderTransform);
Storyboard.SetTargetProperty(anim, new PropertyPath("Matrix"));

Storyboard sb = new Storyboard();
sb.Children.Add(anim);
sb.Duration = TimeSpan.FromSeconds(4);
sb.Begin();
4

3 に答える 3

5

スムーズな平行移動、スケーリング、回転のアニメーションをサポートするMatrixAnimationクラスを実装しました。イージング機能にも対応!http://pwlodek.blogspot.com/2010/12/matrixanimation-for-wpf.htmlで検索します

于 2010-12-06T21:24:41.000 に答える
2

rendersourceを設定し、beginanimationを使用することで、matrixtransformを機能させることができました。

このようなもの:

        this.matrixTransform = new MatrixTransform();
        this.canvas.RenderTransform = this.matrixTransform;


        MatrixAnimationUsingKeyFrames anim = new MatrixAnimationUsingKeyFrames();
        anim.KeyFrames = new MatrixKeyFrameCollection();
        anim.Duration = TimeSpan.FromSeconds(4);

        Matrix fromMatrix = new Matrix(2, 0, 0, 2, 0, 0);
        Matrix toMatrix =  new Matrix(3, 0, 0, 3, 0, 0);

        anim.FillBehavior = FillBehavior.HoldEnd;
        DiscreteMatrixKeyFrame start = new DiscreteMatrixKeyFrame(fromMatrix, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
        DiscreteMatrixKeyFrame end = new DiscreteMatrixKeyFrame(toMatrix, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4)));

        anim.KeyFrames.Add(start);
        anim.KeyFrames.Add(end);

        this.matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, anim);

ただし、すべてのキーフレームの補間を自分でどのように行うのか正確にはわかりません:)

于 2009-12-30T23:08:21.687 に答える
2

私が使用した解決策は回転やせん断に対処できませんが、私は今朝この問題にぶつかりました。リンク

于 2010-04-19T16:15:30.117 に答える