Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate Margin Change in Silverlight

I am animating a border resize in Silverlight however I also need to gradually remove the margin around it (currently 50). Blend doesn't seem to generate a tween for margin change - it just jumps from 50 to 0 in one go. Is there a way to achieve this?

like image 968
James Hughes Avatar asked Sep 23 '09 14:09

James Hughes


1 Answers

The problem is that a Margin is really of type "System.Windows.Thickness" which is NOT a dependency object, thus Left, Top, Right, and Bottom are NOT Dependency Properties and thus cannot be animated using DoubleAnimation (which allows for tweening).

What is used to animate the Margin is an ObjectAnimation which does not tween. This is why you see the margin jump from its original location to its new location. As another common example, the same happens when you try to animate the Visibility property between Visible and Collapsed.

You would either need to do timer based animation in order to animate margin or implement your own Animation type for Thickness objects.

like image 122
markti Avatar answered Oct 05 '22 05:10

markti