Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Image.Source Property

July 28, 2014

Gets or sets the source for the image.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public ImageSource Source { get; set; }
<Image Source="uri"/>

XAML Values

uri

The string provided for the Source property is interpreted as a Uniform Resource Identifier (URI). This is in contrast to an Internationalized Resource Identifier (IRI). This distinction means that characters used to identify a Source that are outside of US-ASCII will need to be encoded.

Relative references are permitted. The relative reference is relative to the XAP file for the application.

Cross-domain URIs are permitted, and specifying the scheme is permitted, but mixing URI schemes is not permitted.

The format-specific filename extensions are not required to be in the URI naming, but if the retrieved file is not determined to be a valid image format, a runtime exception is thrown.

Property Value

Type: System.Windows.Media.ImageSource
A source object for the drawn image.

Dependency property identifier field: SourceProperty

NoteNote:

Windows Phone 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.

In the JavaScript API, the equivalent Source property was set by a string that evaluated as a URI. In the managed API, this property uses an underlying ImageSource instance (actually this is usually a BitmapImage, which is a derived class).

You can set this property in XAML, but in this case you are setting the property as a URI. The XAML behavior relies on underlying type conversion that processes the string as a URI, and calls the BitmapImage(Uri) constructor. This in turn potentially requests a stream from that URI and returns the image source object.

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

The ImageFailed event can occur if the initial Source attribute value in XAML does not specify a valid source.

The following example shows how to create an image.

<Image Source="myPicture.png" />
Image myImage = 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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft