5

I managed to build my storyboard behind code. I don't know how to add easing functions though. I am looking for something like:

DoubleAnimation FadelnTBAnimation = new DoubleAnimation();
FadelnTBAnimation.To = 0;
FadelnTBAnimation.BeginTime = TimeSpan.FromSeconds(0);
FadelnTBAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
FadelnTBAnimation.EasingFunction = EasingMode.EaseInOut; // this line gives an error

How could I apply easing functions with c#?

The reason why I find useful to build the storyboard with code Is because I am applying the same animation to several objects and sometimes it does not work when I bind the target property in XAML.

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Tono Nam
  • 34,064
  • 78
  • 298
  • 470

3 Answers3

5

There is a difference between the easing-function and the easing-mode.

Here is a short example for Win-8 (not WPF):

SineEase easingFunction = new SineEase();
easingFunction.EasingMode = EasingMode.EaseIn;
animation.EasingFunction = easingFunction;
RhodanV5500
  • 1,087
  • 12
  • 16
5

You need to create an instance of IEasingFunction (http://msdn.microsoft.com/en-us/library/system.windows.media.animation.ieasingfunction.aspx). There is a list of implementation classes at the bottom of that documentation entry, the most common of which is probably CubicEase or QuadraticEase.

Paul Wheeler
  • 18,988
  • 3
  • 28
  • 41
2

A simple way to add the easing function in your case would be to just add it to the double animation.

FadelnTBAnimation.EasingFunction = new QuarticEase(); // for example
osborn oliver
  • 51
  • 1
  • 4