Ivan
Ivan

Reputation: 1171

How to translate a control smoothly in wpf?

I use the following code to translate a control in wpf:

TranslateTransform trans = new TranslateTransform();
Studio.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(0, final_point-initial_point, TimeSpan.FromSeconds(2));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);

However, this does just the linear translation which has the same speed all the time. I would like it to start slow, then speed up and finally to slow down again prior to its destination, like a Bezier curve effect. How to do this?

Upvotes: 0

Views: 531

Answers (2)

Clemens
Clemens

Reputation: 128070

Set the DoubleAnimation's EasingFunction property, e.g. to a CubicEase with EasingMode set to EaseInOut:

anim1.EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut };

Upvotes: 2

Giangregorio
Giangregorio

Reputation: 1510

You have to use a DoubleAnimationUsingKeyFrames combined with a SplineDoubleKeyFrame like described in this article:

https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj819806.aspx

Upvotes: 0

Related Questions