In Silverlight, the image control can be used to display images. The usage is pretty straight forward. The syntax of using Image control is shown below:
<Grid x:Name="Layout" Width="250" Height="250" Background="GREEN" >
<Image x:Name="MyImage" Source="/images/basket.jpg" Stretch="Uniform" ></Image>
The Stretch attribute can have the following values:
This will do no modification on the size of the image. If the image size is more than the size of the container, then the image will be cut to fit in the container.
In this case, the image will be expanded to fill the region of the container. The aspect ratio (proportion of width and height) will not be maintained.
This is the default value. In this case, the image will be resized to fit the container, but the aspect ratio will be maintained. So, there may be blank space in the container depending on the width and height of the image and container.
In this case, the image will be resized and will fill the container, but aspect ratio will be maintained by trimming some portion of the image if required.
Width and Height properties
The width and height properties of the image can be used to override the stretch property. If width and height properties are specified, then Stretch property will be ignored.
The clip property of Image control can be used in Silverlight to make certain portion of the image visible and hide some part of it.
See an example of how to display an image in a elliptical form:
<Grid x:Name="Layout" Width="200" Height="220" Background="YELLOW" >
<Image x:Name="MyImage" Source=" Images/AppleTree.png" Stretch="Fill">
<EllipseGeometry x:Name="Ellipse" RadiusX="100" RadiusY="100" Center="100,110"/>
The above code will produce an image like this: