Image::Source Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the source for the image.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
Dependency property identifier field: SourceProperty
Note: |
|---|
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" />
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.
Note: