Export (0) Print
Expand All

DownloadProgressChanged Event (Downloader)

Occurs while content is being downloaded during a download request.

XAML
Cannot be used in XAML.
Scripting
[token = ]downloaderObject.AddEventListener("DownloadProgressChanged", eventhandlerFunction)

AddEventListener Parameters

downloaderObject

object

A particular 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, quotes around the function name are not required. See Remarks.

Event Handler Parameters

sender

object

Identifies the object that invoked the event.

eventArgs

object

This parameter is always set to null.

Remarks

The DownloadProgressChanged event can be used monitor the progress of a download request. The DownloadProgressChanged event occurs whenever the percentage of total content downloaded increases by 0.05 or more, or reaches 1.0. The Completed event occurs when the state of the download request has changed.

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

downloaderObject.AddEventListener("DownloadProgressChanged", "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 progress factor is not carried in event arguments. Instead it is available as a property of the Downloader object that fired the event. That object is always the sender of the event.

Examples

The following JavaScript example shows how to use the DownloadProgress property in a DownloadProgressChanged event handler function:

JavaScript
// Event handler for updating visual progress indicator
function onDownloadProgressChanged(sender, eventArgs)
{
    // Calculate the downloaded percentage.
    var percentage = Math.floor(sender.downloadProgress * 100);

    // Update the Rectangle and TextBlock objects of the visual progress indicator.
    progressText.text = percentage + "%";
    progressRectangle.width = percentage * 2; 
}

The following illustration shows the visual progress indicator at the starting, middle, and ending position of the download.

Visual progress indicator

Visual progress indicator

A visual progress indicator can be constructed from a wide variety of XAML content, including animated objects.

Applies To

Downloader

See Also

Using a Downloader Object
DownloadProgress
Completed

Community Additions

Show:
© 2014 Microsoft