Sets the source value of an object with downloaded content.
| XAML | You cannot use methods in XAML. |
| Scripting | object.setSource(downloader, part)
|
Parameters
| downloader | Downloader The object containing the downloaded
content. |
| part | String The name of the specific part of the downloaded
content package. When the downloaded content package is a Zip file, part refers to the contents of a filename within downloader. If the downloaded content does not represent
packaged content, set part to an
empty string. |
Remarks
The SetSource
method can be used as a way of
setting downloaded media content to the
Source property of the Image and
MediaElement objects, or the
ImageSource property of the
ImageBrush object. The first
parameter, downloader, identifies the Downloader object representing the downloaded content. The second parameter, part, identifies the specific part to retrieve
within the downloaded content. If the downloaded content does not represent
packaged content, such as a Zip file, part must be set to an
empty string. The following
JavaScript example shows how to use the SetSource method to set the
Source property of an Image object to the downloaded content:
| JavaScript |
// Event handler for the Completed event.
function onCompleted(sender, eventArgs)
{
// Retrieve the Image object.
var myImage = sender.findName("myImage");
// Set the Source property to the contents of the downloaded object,
// In this case, since the downloaded content represents a single image file, promo.png,
// the part parameter is set to an empty string.
myImage.setSource(sender, "");
}
|
Silverlight provides the ability to download content as a package, which is a collection of independent files
containing XAML content, media assets, and other application data. The Zip
file format is supported as a download package. The following diagram
illustrates a collection of application content contained within a Zip download package:
Once the package is successfully downloaded, you can use methods, such as
GetResponseText,
SetSource, and
CreateFromXamlDownloader, to selectively
retrieve a specific named part of the package. In this case, a
part reference is the filename reference of the individual content within
the package, such as "rotation01_green.png".
You can use the SetSource method to retrieve a specific part within the downloaded
content package. When the downloaded content package is a Zip file, the SetSource
method allows you to retrieve the contents of a filename within the Zip
file. The following JavaScript example shows how to use the SetSource method to set the Source property of an Image object to
a specified part within the downloaded content:
| JavaScript |
function onDownloadCompleted(sender, eventArgs)
{
// Determine whether the download was successful.
if (currentDownloadProgress != 1)
{
alert("Failed to succesfully download zip file");
return;
}
// Retrieve the XAML content from the downloaded package file.
var jacketBrowserXaml = sender.getResponseText("jacketBrowser.xaml");
// Create the objects from the XAML content.
var jacketBrowser = control.content.createFromXaml(jacketBrowserXaml);
// Add downloaded XAML content to the control.
sender.findName("root").children.insert(0, jacketBrowser);
// Retrieve a reference to the Image object representing the jacket.
var jacketImageSlice = sender.findName("jacketSlice");
// Set the Source property of the Image object to the specific jacket image
// within the downloaded Zip package file.
jacketImageSlice.setSource(sender, "rotation01_green.png");
}
|
Applies To
Image,
ImageBrush,
MediaElement
See Also
Downloader,
Using a Downloader Object