QUICKSTARTS
[This topic is pre-release documentation and is subject to change in future releases of Microsoft Silverlight.]

images

The Image element enables you to display bitmap images in Silverlight.

This document contains the following sections.

the Image element

The Image element provides a convenient way to display JPG and PNG images in Silverlight. To display an image, set the Source property of the Image object to specify the path for your image file source. The following example uses an Image element to display a 141 by 131 pixel bitmap image. Because the Image Width and Height properties are not specified, the bitmap is displayed at its native size.

<Canvas Width="300" Height="300"
   xmlns="http://schemas.microsoft.com/client/2007"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Image Source="star.png" />
</Canvas>

the Stretch property

When the size of the Image element and the size of its bitmap are different, the Stretch property determines how the bitmap is stretched to fit the Image element. The Stretch property takes the following values: None, Fill, Uniform, UniformToFill. The following example demonstrates the None, Uniform, and Fill settings.

<Canvas Width="300" Height="300"
   xmlns="http://schemas.microsoft.com/client/2007"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Background="White">
  <Image Source="star.png" Stretch="None"
     Height="100" Width="200" Canvas.Left="100" />
  
  <Image Source="star.png" Stretch="Fill"
     Height="100" Width="200" Canvas.Top="100" Canvas.Left="100" />   
  
  <Image Source="star.png" Stretch="Uniform"
     Height="100" Width="200" Canvas.Top="200" Canvas.Left="100" /> 
     
  <TextBlock Canvas.Left="5" Canvas.Top="0">None</TextBlock>
  <TextBlock Canvas.Left="5" Canvas.Top="100">Fill</TextBlock>
  <TextBlock Canvas.Left="5" Canvas.Top="200">Uniform</TextBlock> 
</Canvas>

For more information about the different stretch settings, see the Stretch property reference in the Silverlight SDK.

other ways to use bitmaps

To use a bitmap as a background, use the ImageBrush object. See drawing and painting for more information.

what's next

The next topic, text, describes how to use the TextBlock element to add text to your Silverlight content.

Page view counter