CreateFromXamlDownloader Method

Creates XAML content dynamically using downloader content.

XAML
Cannot use methods in XAML.
Scripting
retval = silverlightObject.content.CreateFromXamlDownloader(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.

Return Value

object

An object reference if the XAML content was successfully created; otherwise, returns null.

Remarks

This method is available on the content sub-object of a Silverlight plug-in instance.

The CreateFromXamlDownloader method creates objects from XAML content dynamically by using the downloaded content in the Downloader object. If successful, the CreateFromXamlDownloader method returns an object reference, which you can then add to the existing Silverlight object hierarchy. You can create a single Silverlight object, such as a TextBlock, or an entire tree of Silverlight objects.

Note   The CreateFromXamlDownloader method is more efficient that using CreateFromXaml with downloaded content, since it avoids have to copy downloaded content from the GetResponseText method return value to a temporary buffer and then back again for use by the XAML parser.

XAML content created by using the CreateFromXamlDownloader method is not rendered until it is added to an object using the Add method. The following illustration shows the relationship between the Silverlight object hierarachy and the downloaded XAML content before and after the content is added to the object hierarchy.

Silverlight object hierarchy

Silverlight object hierarchy

Examples

The following JavaScript example shows how to add XAML content to an existing Canvas object using the CreateFromXamlDownloader method. Because the downloaded content does not represent packaged content, the part parameter for CreateFromXamlDownloader is set to an empty string:

JavaScript
// Event handler for the Completed event.
function onCompleted(sender, eventArgs)
{
    // Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();
    // Retrieve the XAML fragment and create an object reference.
    // In this case, since the downloaded content represents a single file, OK_button.xaml,
    // the part parameter is set to an empty string.
    var xamlFragment = slPlugin.content.createFromXamlDownloader(sender, "");
    // Add the XAML object as a child of the root Canvas object.
    var root = sender.findName("rootCanvas");
    root.children.add(xamlFragment);
}

You can also use the CreateFromXamlDownloader method to retrieve a specific part within the downloaded content package. When the downloaded content package is a Zip file, the CreateFromXamlDownloader method retrieves the contents of a filename within the Zip file.

The following JavaScript example shows how to use the CreateFromXamlDownloader method, using the part parameter to reference as specified part within the downloaded content:

JavaScript
// Event handler for the Completed event.
function onCompleted(sender, eventArgs)
{
    // Retrieve a reference to the plug-in.
    var slPlugin = sender.getHost();
    // Retrieve the specified XAML file from the packaged downloader content,
    // and create an object reference.
    var xamlFragment = slPlugin.content.createFromXamlDownloader(sender, "OK_button.xaml");
    // Add the XAML object as a child of the root Canvas object.
    var root = sender.findName("rootCanvas");
    root.children.add(xamlFragment);
}

Applies To

Silverlight Plug-in

See Also

Using a Downloader Object
Silverlight XAML Syntax