Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  


How to control the frame rate for WPF animations

Animations are very cool, but they can cause a high CPU load. One reason could be a missing hardware acceleration due to a old graphics adapter or a software rendering constraint. Another reason could be the the high frame rate of animations that is set to 60 fps by default.

You can easily lower the framerate for all animations by overriding the DesiredFrameRate property of the timeline. Just add the following code to your project and play around with the setting to find a good tradeoff between performance and aesthetic.

 
Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline),
   new FrameworkPropertyMetadata { DefaultValue = 30 });
 
 

Or you can set the framerate individually for each animation in XAML, using the following code:

 
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" 
                 From="1.0" To="0.5" Timeline.DesiredFrameRate="30" />
 
 




Last modified: 2010-03-02 00:31:02
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
karthik
Commented on 4.February 2010
Good tutorial for WPF
RomanK
Commented on 1.March 2010
Thank you for this. And seeing it's defined by a property, we can even define this individually for animations (e.g. to make soft animations smoother or reduce CPU load on fast animations). In XAML this can look like this:

<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.5" From="1.0" To="0.5" Timeline.DesiredFrameRate="30" />

Why not add this to your tutorial?
Christian Moser
Commented on 2.March 2010
Thanks Roman! I added your XAML example.
Atul Raina
Commented on 28.March 2010
Adjusting frame rates was always a mess for me being a novice flash programmer , the way you expressed the topic out here would help me in getting through. Thanks a lot and your knowledge share is appreciating
Iyappan Mani
Commented on 24.July 2010
Nice tutorial
3bdeen tb3n
Commented on 25.July 2010
klam zy el fol wallahy , ana msh 3aref a2olko eh > < ento nas zy el fol , 5llo balko mn nfsko w isa htb2o 7d kowyes
3bdeen tb3n
Commented on 25.July 2010
klam zy el fol wallahy , ana msh 3aref a2olko eh > < ento nas zy el fol , 5llo balko mn nfsko w isa htb2o 7d kowyes
Qualitatserz...
Commented on 11.August 2010
Does a round gauge control (controls for WPF) uses animation to move the indicator??? thanks
MOSER
Commented on 23.August 2010
I apprieciate your feedback but I cant explain it anymore in depth because I just copy and pasted this from another website
MOSEY
Commented on 23.August 2010
I apprieciate your feedback but I cant explain it anymore in depth because I just copy and pasted this from another website
subbu
Commented on 6.September 2010
Good
Rev
Commented on 21.September 2010
Hi
Cool Article, but I have real big problem with animations.(its about framrates)
raj
Commented on 29.March 2011
Hi
Cool Article, but I have real big problem with animations.(its about framrates)
shivraj...
Commented on 19.July 2011
GOOD TUTORIAL..
Pradip
Commented on 4.August 2011
its good but how to add in user control please tell
swetha sreepada
Commented on 13.September 2011
Thank you..nice tutorial

Name
E-Mail (optional)
Comment