Passing Parameters into Silverlight

There are a number of different methods for passing parameters into Silverlight:

o     Query string
o     InitParams property
o     JavaScript function calls
 
InitParams

The easiest way to pass parameters into a Silverlight application is with the InitParams property on the Silverlight control. Values passed in using this method need to be represented in the format Name=Value and separated by commas.
 
For example:

Name=Alex,Age=28,Country=Australia
To use the IntitParams property, just add params to the object tag like so:
<param name="InitParams" value="name=alex,sex=male" />
Input values can then be retrieved by iterating through the InitParams keys collection in

App.xaml.cs:

 //Initialization parameters.
foreach (String key in e.InitParams.Keys)
{
string strKey = key;
string strValue=e.InitParams[key];
}

Query String

Another method of passing parameters to a Silverlight is with the query string. The following code shows you how to iterate through all the query string values:

 //URL Params
foreach (String key in System.Windows.Browser.HtmlPage.Document.QueryString.Keys)
{
string KeyName = key;
string strValue=System.Windows.Browser.HtmlPage.Document.QueryString[key];
}

No comments:

Post a Comment