Export (0) Print
Expand All

CreateFromXamlDownloader

Silverlight

Creates XAML content dynamically by using downloader content.

retval = silverlightObject.content.CreateFromXamlDownloader(downloader, part)

downloader

Downloader

The Downloader object that initiated the request for 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. part is not an optional parameter; you must specify at least the empty string or a syntax error will result.

Type: object

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

This method is available on the content subobject 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.

NoteNote:

CreateFromXamlDownloader is more efficient than using the CreateFromXaml method with downloaded content. This is because the CreateFromXamlDownloader internal implementation copies downloaded content from the Downloader request and routes it directly to the XAML parser, without requiring an intermediate buffer or variable.

XAML content created by using the CreateFromXamlDownloader method is not rendered until it is added to an object by using the Add method.

CreateFromXaml and CreateFromXamlDownloader have other considerations regarding connecting trees and namescopes, which apply to both methods. For details, see Remarks in CreateFromXaml.

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

// Create the 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, because 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 of the downloaded content package. When the downloaded content package is a ZIP file, the CreateFromXamlDownloader method retrieves the contents of a file name in the ZIP file.

The following JavaScript example shows how to use CreateFromXamlDownloader by using the part parameter to reference a specified part in the downloaded content:

// Create the 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);
}

Community Additions

ADD
Show:
© 2014 Microsoft