Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the animation smoother through code in WPF?

Tags:

c#

animation

wpf

How do we do the smooth animation. I have the code as below.

ThicknessAnimation anima = 
    new ThicknessAnimation(new Thickness(0), new Thickness(0, 25, 0, 0), 
        new Duration(new TimeSpan(0, 0, seconds)), FillBehavior.HoldEnd);                  

pdRod.BeginAnimation(Border.MarginProperty, anima);

Its working, but not smooth enough. How to do it smooth?

Thanks,

like image 1000
Ershad Avatar asked Oct 06 '09 10:10

Ershad


3 Answers

To do this in code, you would use the Timeline.SetDesiredFrameRate(Timeline,int?) method, like this:

ThicknessAnimation anim = ...;
Timeline.SetDesiredFrameRate(anim, 60); // 60 FPS

Passing null for the second argument tells the system to control the frame rate.

like image 108
Drew Noakes Avatar answered Oct 12 '22 19:10

Drew Noakes


If you are using StoryBoard, use Timeline.DesiredFrameRate attached property.

like image 32
user2516081 Avatar answered Oct 12 '22 21:10

user2516081


Try to adjust the attached property Timeline.DesiredFrameRate to your needs. An higher framerate will reduce the tearing you might see.

like image 31
Julien Lebosquain Avatar answered Oct 12 '22 19:10

Julien Lebosquain