The InitParameters Property of the SilverlightControl

When using Silverlight from within SharePoint you have to place a SilverlightControl on your web part, custom field type or application page. By setting the Source property you indicate which Silverlight application to run.

You can use the InitParameters property to pass values from SharePoint to Silverlight. But there is something weird about this property: at the Server side this property is a string and at the Silverlight side this property is a dictionary of KeyValuePairs where the value is always a string.

To construct the string so that it can easily be converted to a dictionary of KeyValuePairs by Silverlight you have to separate the different parameters by a comma and you have to place an equal sign between key and value:

silverlightControl.InitParameters = "key1=value1,key2=value2,key3=value3";

Don't place a blank between the comma and the next key because it will be added as the first character in the next key name.

In the App.xaml code behind you can then retrieve the keys and values from the EventArgs argument:

string value1 = null;

string value2 = null;

if (e.IniParams != null && e.InitParams.Count > 0)

{

value1 = e.IniParams["key1"];

value2 = e.IniParams["key2"];

}

If you need these values in your code behind of your xaml pages, pass them within the constructor of the page:

this.RootVisual = new Page(value1, value2);

Be aware that you cannot pass large chunks of data in the InitParameters property.