Partager via


Source (Silverlight Plug-in)

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

Gets or sets the Uniform Resource Identifier (URI) of the XAML file that specifies the XAML content to render.

value = silverlightObject.Source
silverlightObject.Source = value

Property Value

Type: string

The URI of the XAML file or XAML scripting tag that contains the content to load into the Silverlight plug-in. Generally, this is a reference to a XAML file. The URI can also include a # (number sign) prefix to specify an inline XAML reference, as explained in the "Remarks" section.

This property is read/write. The default value is null.

Managed Equivalent

Source - but read-only from managed code. Can be set through instantiation, or in some cases through Application.RootVisual.

Remarks

Changing the Source value at run time is permitted. In terms of performance in Silverlight for the JavaScript API, this operation is equivalent to unloading and reloading the Silverlight plug-in. In some cases, using the CreateFromXaml method and rebuilding the object tree below the original root will provide better performance than resetting the Source property.

The string provided for the Source property is interpreted as a URI instead of an Internationalized Resource Identifier (IRI). This distinction means that characters used to identify a Source that are outside the US-ASCII character set will have to be encoded.

The # (number sign) prefix in the string identifies a Source that references inline XAML.

Example

The following JavaScript example of a modified CreateSilverlight.js file shows how to load a XAML file by setting the source initialization parameter to the name of the XAML file, HelloWorld.xaml.

function createSilverlight()
{  
    Sys.Silverlight.createObject(
        "HelloWorld.xaml",                  // Source property value.
        parentElement,                      // DOM reference to hosting DIV tag.
        "myPlugin",                         // Unique plug-in ID value.
        {                                   // Plug-in properties.
            width:'1024',                   // Width of rectangular region of plug-in, in pixels.
            height:'530',                   // Height of rectangular region of plug-in, in pixels.
            inplaceInstallPrompt:false,     // Determines whether to display verbose install prompt if invalid version detected.
            background:'OldLace',           // Background color of plug-in.
            isWindowless:'true',            // Determines whether to display plug-in in windowless mode.
            framerate:'30',                 // MaxFrameRate property value.
            version:'1.0'                   // Plug-in version to use.
        },
        {
            onError:null,                   // OnError property value -- event handler function name.
            onLoad:onLoad                   // OnLoad property value -- event handler function name.
        },
        null);                              // Context value -- event handler function name.
}

Notice that when the Source property or source parameter value refers to a file reference, it is set to the directory location of the XAML file relative to the HTML file.

The following XAML example shows the XAML content that corresponds to the file that is referenced by the Source property value in the previous HTML example.

<!-- HelloWorld.xaml -->
<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <TextBlock
    Foreground="Maroon" FontFamily="Verdana" FontSize=s"24" FontWeight="Bold"
    Text="Hello, world" />
</Canvas>

You can also use the Source property to load XAML content after the Silverlight plug-in has been created. When you reload XAML content, the existing XAML content in the plug-in is no longer valid. The following JavaScript example shows an event handler function that reloads the XAML content.

// Event-handling function for reloading the XAML content on the page.
function reloadContent(plugin)
{
    // Define the XAML content.
    plugin.source = "HelloWorld.xaml";
}
NoteNote:

The XAML content renders immediately after you set the Source property. However, extremely large XAML files may result in a delay because of the time required to parse the XAML.

The script syntax shown is for using the Source property at run time. You can also set the property during initiation, using either object param syntax or the silverlight.js helper functions. See Source (Silverlight Plug-in Object).

Applies To

Silverlight Plug-in