Exporter (0) Imprimer
Développer tout

SetSource (Image)

Silverlight

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Sets the source value of an Image object with downloaded content.

object.SetSource(downloader, part)

downloader

Downloader

The Downloader object that contains 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 file name in downloader. If the downloaded content does not represent packaged content, set part to an empty string.

BitmapSource.SetSource - use a stream obtained from WebClient as input.

The SetSource method sets the downloaded image content to the Source property of an Image object. Equivalent SetSource methods exist on ImageBrush (for ImageSource) and MediaElement (for Source). The first parameter, downloader, identifies the Downloader object that represents the downloaded content. The second parameter, part, identifies the specific part to retrieve from 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.

// 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, because 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 that contain XAML content, media assets, and other application data. The .zip file format is supported as a download package.

When the package has been successfully downloaded, you can use methods such as GetResponseText, SetSource, and CreateFromXamlDownloader to selectively retrieve a named part of the package. When the downloaded content package is a .zip file, the SetSource method lets you retrieve the contents of a file name from within the .zip file archive.

The following JavaScript example shows how to use the SetSource method to set the Source property of an Image object to a specified part ("rotation01_green.png") of the downloaded content.

function onDownloadCompleted(sender, eventArgs)
{
    // Retrieve the XAML content from the downloaded package file.
    var jacketBrowserXaml = sender.getResponseText("jacketBrowser.xaml");
    // Create the objects from the XAML content.
    var jacketBrowser = plugin.content.createFromXaml(jacketBrowserXaml);

    // Add downloaded XAML content to the root Canvas of the plug-in.
    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");
}

Ajouts de la communauté

AJOUTER
Microsoft réalise une enquête en ligne pour recueillir votre opinion sur le site Web de MSDN. Si vous choisissez d’y participer, cette enquête en ligne vous sera présentée lorsque vous quitterez le site Web de MSDN.

Si vous souhaitez y participer,
Afficher:
© 2014 Microsoft