Condividi tramite


Completed (Downloader)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when a download request completes with content.

[token = ]downloaderObject.AddEventListener("Completed", eventhandlerFunction)

Arguments

AddEventListener Parameters

downloaderObject

object

A specific Downloader object.

token

integer

A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token.

eventhandlerFunction

object

The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotation marks around the function name are not required. (See the "Remarks" section.)

Event Handler Parameters

sender

object

The object that invoked the event.

eventArgs

object

This parameter is always set to null.

Managed Equivalent

None. Downloader does not exist in the managed API. Generally you can use WebClient for downloads, which provides equivalent events and functionality.

Remarks

The Completed event occurs after a download request has completed and returned content, asynchonous to a call to the Send method of the Downloader object. The Status and StatusText properties reflect the HTTP status code values for the completed download request.

You can also add handlers in script by using a quoted string for the event handler name, as follows:

downloaderObject.AddEventListener("Completed", "eventhandlerFunction")

This syntax also returns a token. However, the token is not an absolute requirement for removing the handler in cases where the handler was added by using a quoted string. For details, see RemoveEventListener.

The Completed event occurs after you send a download request, and when a download request returns with content. Typically you use a Completed handler to access the response text that will then be available on the Downloader object. To do this, you can use either the ResponseText property or the GetResponseText method, depending on whether the download represents a package and therefore you need to specify a part.

Example

The following JavaScript example shows how to define a Completed event handler function that accesses the downloaded content. In this case, the content is a single item download (not a package).

// Event handler for the Completed event.
function onCompleted(sender, eventArgs)
{
    // Retrieve downloaded XAML content.
    var xamlFragment = sender.ResponseText;

    // Create the objects from the XAML content.
    var plugin = sender.getHost();
    var button = plugin.content.createFromXaml(xamlFragment);

    // Add downloaded XAML content to the root Canvas of the plug-in.
    var rootCanvas = sender.findName("rootCanvas");
    rootCanvas.children.add(button);
}

Applies To

Downloader