Wednesday, August 26, 2009

Text not scaling properly during animation in Silverlight

If you are facing the problem where you text is not scaling properly and the animation is not coming smooth then in this kind of situation you have to use something which can find the nearest neighbor and convert the values in accordance with this nearest neighbor.

If you are using Silverlight then you can do this very easily by typing just one line of code.

For Silverlight 2 you have to type

RenderOptions.TextRenderingMode = “RenderForAnimation”

For Silverlight 3 you have to type

TextOptions.TextHintingMode = "Animation"

Both of these ensure that the text animation is proper, if you don’t use these properties then you will find sometime when you are applying some scaling or any other rendering transformation on any container which also contains some text element then this text element inside the container will also scale.

I will give main emphasis on Silverlight 3 property i.e TextOptions.TextHintingMode

This property takes one of two possible values: Animated or Fixed.

“Animated optimizes for animation by using a more efficient, but less visually precise, smoothing algorithm. Text is still readable and the loss of precision is not that severe.”

Fixed uses an algorithm that is optimized for visually precise text smoothing, but can lead to performance issues. For example, when animations are applied to properties of a text element, in particular FontSize, you might see jitters. When transforms, positioning, or projections are applied to text elements, you might see performance issues. Fixed is the default.

You can apply this property to a layout container and the setting will apply to any text element within that container. However, in general, you should apply this property directly to a text element, such as a TextBlock, TextBox, or Glyphs, where the animations applied will only affect the text.

Happy Programming!!!!!!!!!!!!!!!

0 comments :

Post a Comment