InitParams
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Gets or sets an optional set of user-defined initialization parameters. This property is write-once during instantiation, and read-only to scripting at run time in the Silverlight object model.
value = silverlightObject.InitParams
Property Value
Type: string
A string that represents a set of user-defined initialization parameters. The string format of the value is user-defined.
This property is settable only as an initialization parameter, and is read-only for scripting thereafter. The default value is null.
Managed Equivalent
InitParams - rather than being on the SilverlightHost, the initParams are transmitted through event data of Startup.
Remarks
The InitParams property cannot be set after initialization. The initParams initialization parameter specifies user-defined parameter values when you instantiate an instance of the Silverlight plug-in within an HTML page, by calling either the Silverlight.CreateObject or CreateObjectEx functions. The initparams values can be retrieved at run time by accessing the plug-in's InitParams property. InitParams provides a convenient way to pass your own string values from the HTML Document Object Model (DOM) into the Silverlight object model.
Generally, if you have more than one string atom to pass, you would use a character (such as a comma) as a delimiter in the combined InitParams string, and then split the string into atoms again from your JavaScript code.
The script syntax shown is for using the InitParams property at run time. You can also set the property during initiation, using either object param syntax or the silverlight.js helper functions. See InitParams (Silverlight Plug-in Object).
Example
The following JavaScript example shows how to specify the initParams parameter value in the user-defined CreateSilverlight method in CreateSilverlight.js.
function createSilverlight()
{
Silverlight.createObject(
"plugin.xaml", // Source property value.
parentElement, // DOM reference to hosting DIV tag.
"myPlugin", // Unique plug-in ID value.
{ // Plug-in properties.
width:'600', // Width of rectangular region of plug-in in pixels.
height:'200', // Height of rectangular region of plug-in in pixels.
version:'1.0' // Plug-in version to use.
},
{ }, // No events defined -- use empty list.
"param1, param2"); // InitParams property value.
}
To access the value of the initParams initialization parameter values at run time, use the InitParams property of the plug-in. The following JavaScript example shows how to retrieve the parameter values by using the InitParams property.
function onLoaded(sender, eventArgs)
{
// Retrieve a reference to the plug-in.
var plugin = sender.getHost();
// Retrieve the InitParams value and split comma-delimited string.
var params = plugin.initParams.split(",");
// Display the parameter values.
var msg = "Params: ";
for (var i = 0; i < params.length; i++)
{
msg += params[i] + " ";
}
alert(msg);
}