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>
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>
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:
- RectangleGeometry
- GeometryGroup
- LineGeometry
- PathGeometry
Thank you,
--Mike Snow
Subscribe in a reader