Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #80 – How to Crop an Object

If you only want to display part of an object you can do this through the Clip property. The clip that you define is the area of the object that you want to be rendered. For example, say you have a rectangle defined like this:

<Rectangle Fill="DarkGoldenrod" Height="100" Width="200" StrokeThickness="3" Stroke="Black"></Rectangle>

 image

If you only want to show part of the rectangle you can apply a clip region to it like this:

<Rectangle Fill="DarkGoldenrod" Height="100" Width="200" StrokeThickness="3" Stroke="Black">
            <Rectangle.Clip>
                       <EllipseGeometry Center="0,0" RadiusX="80" RadiusY="80" />               
            </Rectangle.Clip>
</Rectangle>

image

You will noticed I used an EllipseGeometry and centered it in the upper-left corner. The result is a 1/4 circle 80x80 in size. In addition to EllipseGeometry you can also use:

  1. RectangleGeometry
  2. GeometryGroup
  3. LineGeometry
  4. PathGeometry

Thank you,
--Mike Snow

Subscribe in a reader

Comments

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight Tips of the

# January 9, 2009 2:37 PM

Microsoft Weblogs said:

If you only want to display part of an object you can do this through the Clip property. The clip that

# January 9, 2009 2:51 PM

GearWorld said:

Make ElipseGeometry available in Blend 2 and make sure we can Clip an image that will be resizable in a grid without and the clipper will follow the size else we have to do it by code which is not really the point of doing this.

# January 9, 2009 9:26 PM

Dew Drop - January 10, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - January 10, 2009 | Alvin Ashcraft's Morning Dew

# January 10, 2009 4:28 PM

Community Blogs said:

In this issue: Michael Washington, Pete Brown(2), Shawn Wildermuth(2), Jesse Liberty, Mike Snow, Terence

# January 10, 2009 9:03 PM

Wie man ein Object zuschneidet at Programming with Silverlight, WPF & .NET said:

Pingback from  Wie man ein Object zuschneidet at Programming with Silverlight, WPF &amp; .NET

# January 14, 2009 7:54 AM

Visual Web Developer Team Blog said:

Most Recent Posts: Tip #93 - Reading XML with Silverlight Tip #92 - How to Load Images from a Stream

# February 10, 2009 6:25 PM