1

Border の動きをアニメーション化できます。

private void MoveTo(Border target, double newX, double newY)
{
    Vector offset = VisualTreeHelper.GetOffset(target);
    var top = offset.Y;
    var left = offset.X;
    TranslateTransform trans = new TranslateTransform();
    target.RenderTransform = trans;
    DoubleAnimation anim1 = new DoubleAnimation(0, newY - top, TimeSpan.FromMilliseconds(500));
    DoubleAnimation anim2 = new DoubleAnimation(0, newX - left, TimeSpan.FromMilliseconds(500));
    trans.BeginAnimation(TranslateTransform.YProperty, anim1);
    trans.BeginAnimation(TranslateTransform.XProperty, anim2);
}

しかし、画像を拡大する印象を与えるために、高さと幅、および位置の増加をアニメーション化できるようにしたいと考えています(私の場合と上記の例では Border に含まれています))。

これはコードビハインドで可能ですか?


OK、スケール変換を試みましたが、何もしていないようです - ストーリーボードが必要ですか?

    private void Zoom(Border target)
    {   
        TranslateTransform trans = new TranslateTransform();
        target.RenderTransform = trans;
        DoubleAnimation anim1 = new DoubleAnimation(1, 2, TimeSpan.FromMilliseconds(1000));
        DoubleAnimation anim2 = new DoubleAnimation(1, 2, TimeSpan.FromMilliseconds(1000));
        trans.BeginAnimation(ScaleTransform.ScaleXProperty, anim1);
        trans.BeginAnimation(ScaleTransform.ScaleYProperty, anim2);
    }
4

2 に答える 2

8

ズームにはスケール変換を使用することをお勧めしますが、W/H のアニメーション化を主張する場合は、それを実行できます。これらは通常の DP であるため、標準の DoubleAnimation/DoubleAnimationUsingKeyFrames を使用してアニメーション化できます。

DoubleAnimation doubleAnimation = new DoubleAnimation(100, 200, new Duration(TimeSpan.FromMilliseconds(500)));
        this.BeginAnimation(FrameworkElement.WidthProperty, doubleAnimation);
于 2012-09-23T11:23:03.787 に答える
1

&アニメーションを使用するScaleTransform必要はありません。境界線に影響を与えるため、内側の画像も引き伸ばされます。HeightWidthScaleTransformVisualTree

    private void Zoom(Border target)
    {
        ScaleTransform trans = new ScaleTransform();
        target.RenderTransform = trans;
        // if you use the same animation for X & Y you don't need anim1, anim2 
        DoubleAnimation anim = new DoubleAnimation(1, 2, TimeSpan.FromMilliseconds(1000));
        trans.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
        trans.BeginAnimation(ScaleTransform.ScaleYProperty, anim);

    }
于 2012-09-23T11:15:05.970 に答える