WPF TranslateTransform [英] WPF TranslateTransform

查看:530
本文介绍了WPF TranslateTransform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着使用TranslateTransform类对Y轴网格移动图像。我需要这个movment是光滑的,所以我不能用SetMargin或SetCanvas。我尝试这code背后:

Im trying to use the TranslateTransform class to move a image on a Grid on Y axis. I need this movment to be smooth so i can not use SetMargin or SetCanvas. I try this in code behind:

public void MoveTo(Image target, double oldY, double newY)
{
    var trans = new TranslateTransform();
    var anim2 = new DoubleAnimation(0, newY, TimeSpan.FromSeconds(2))
                    {EasingFunction = new SineEase()};
    target.RenderTransform = trans;
    trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}

我想用(一个Image控件)对象放在一个网格。
 第一次,一切工作正常。
问题是当我再次尝试使用相同的函数来移动对象。
该对象(Image控件)先移动到起始位置(初始Y坐标),然后是动画开始。

The object i want to use (a Image control) is placed on a Grid. For the first time everything works fine. The problems comes when i try to move the object again using the same function. The object (a Image control) first move to the start position (initial Y coordinate) then the animation begins.

这岂不是suposed的TranslateTransform到(Margin属性在我的情况)改变的坐标呢?

Is it not suposed for the TranslateTransform to change the coordinates (in my case the Margin property) too?

感谢您。

推荐答案

该转换不会改变原来的values​​.they是你的原点。如果你想血统的新点,每次你移动你能处理动画完成的事件。或者从您的转换,你可以得到你的当前偏移,使您的新起点为动画。

The transform does not change the original values.they are your point of origin. If you want a new point of origin each time you move you can handle the animation completed event. Or from your transform you can get your current offset and make that your new start point for the animation.

在换句话说,你的初始值将永远是你的最后一步将值

In other words your start values would always be your last move to values

这篇关于WPF TranslateTransform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆