Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
Image Class

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
Image Class

Represents a control that displays an image.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public NotInheritable Class Image _
    Inherits FrameworkElement
Visual Basic (Usage)
Dim instance As Image
C#
public sealed class Image : FrameworkElement
XAML Object Element Usage
<Image .../>
NoteNote:

Silverlight does not support all image formats. See BitmapImage for information on the types of image sources and formats that can be used for an Image.

You can set the Source by specifying an absolute URL (e.g. http://contoso.com/myPicture.jpg) or specify a URL relative to the XAP file of your application.

If Height and Width are not set, the Image displays with the natural height and width of its source image file.

If the Source property is set to an invalid format, or is specified to an ImageSource that was not properly constructed, then the ImageFailed event is raised.

An Image potentially has asynchronous behavior. This happens if the Source is set either by directly specifying a URI in XAML, or is set to a BitmapImage that is being newly constructed using a URI. Until the source is resolved and the image source decoded, layout will occur but the image will be treated as an element of 0 size if it did not specify Height and Width, or as a blank area of that size if Height and Width are specified. Once the URI is resolved and the image source is decoded, another layout pass is initiated.

Silverlight uses bitmap caching. Therefore, if an image has been requested by URI before, the cached and decoded image is used again rather than initiating a new request from the URI.

See BitmapImage for information on the types of image sources and formats that can be used for an Image.

The following example shows how to create an image.

<Image Source="myPicture.png" />
C#
Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("myPicture.jpg", UriKind.RelativeOrAbsolute));
LayoutRoot.Children.Add(myImage);
Visual Basic
Dim myImage As Image = New Image
myImage.Source = New BitmapImage(New Uri("myPicture.jpg", UriKind.RelativeOrAbsolute))
LayoutRoot.Children.Add(myImage)

In this example, the Source property is used to specify the location of the image you want to display. You can set the Source by specifying an absolute URL (e.g. http://contoso.com/myPicture.jpg) or specify a URL relative to the XAP file of your application. So for the previous example, you would need to have the XAP file in the same folder as myPicture.png.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker