Export (0) Print
Expand All

Source Property (Image)

Gets or sets the source for the image by specifying the URI for its image file location.

<object Source="string" .../>
value = object.Source
object.Source = value

Property Value


The source of the drawn image, as a URI.

This property is read/write. The default value is null.


The Source property can be used to reference images in the JPEG and PNG file formats.

The string provided for the Source property is interpreted as a Uniform Resource Identifier (URI). This is in contrast to an Internationalized Resource Identifiers (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 starting location for the relative reference is the HTML page that contains the current Silverlight plug-in.

Cross-domain URIs are permitted, and specifying the scheme is permitted, but mixing URI schemes (such as accessing an HTTPS image from a Silverlight plug-in hosted on an HTTP-served HTML page) is not permitted. The JPEG and PNG filename extensions are not required to be in the URI, but if the retrieved file is but if the retrieved file is not determined to be either in JPEG or PNG format, a runtime exception is thrown.

If you are not accessing cross-domain sources, you should consider using SetSource rather than setting Source directly. This provides the advantage of being able to track the download. Also, you can download multiple images as a package and access parts from within the package.

In JavaScript, you can set the value to null or empty string at runtime to cause the image to unload and no longer render. Doing so does not fire an ImageFailed event. In contrast, setting Source to a URI value that does not resolve will fire an ImageFailed event. Also, a SetValue error is thrown, even if ImageFailed is handled.

You can specify an initial XAML value of "" (empty string) and then set the value in script at a later time, to create a nonrendering placeholder.

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

Applies To


See Also

Imaging Overview
Using a Downloader Object

Community Additions

© 2015 Microsoft