Animating clipping area in Silverlight

Posted by Corey on January 8, 2009 at 10:33 am.

The other day I wanted to animate a clipping area.  The answer is to define the Clip property of an object with RectangleGeometry or EllipseGeometry and then animate properties on the geometry. 

The below example shows a RectangleGeometry clipping area being moved over an image.  In the MouseMove event, I am setting the values of RectangleGeometry’s TranslateTransform property.

The XAML

animate_clip_xaml

  • The clipping area of the Image is defined within the <Image.Clip> property
  • Values in the Rect attribute of the RectangleGeometry are PositionX, PositionY, Widht, Height.  In this case the clipping area is in the middle of the image
  • A TranslateTransform is defined for the RectangleGeometry.Transform.  To make it easy to reference from the code, make sure to define a value for the x:Name attribute.

The Code

animate_clip_code

  • In the MouseMove event reset the value for the Rect if the Left and Top values are not zero.
  • Then set the values for the TranslateTransform.

The Example

image

http://www.85turns.com/silverlight/AnimateClippingGeometry.html

4 Responses to “Animating clipping area in Silverlight”

Leave a Reply