Silverlight cannot be like flash, directly like XXX. xap? Name = 123 is used to pass the parameter, but is implemented in another way:
HTML (highlight ):
<Object Data = "data: Application/x-silverlight-2," type = "application/x-silverlight-2" width = "100%" Height = "100%">
<Param name = "Source" value = "clientbin/initparams. xap? Color = Red "/>
<Param name = "onerror" value = "onsilverlighterror"/>
<Param name = "background" value = "white"/>
<Param name = "minruntimeversion" value = "3.0.40624.0"/>
<Param name = "autoupgrade" value = "true"/>
<Param name = "initparams" value = "name = Jimmy. Yang, age = 30"/>
<A href = "http://go.microsoft.com/fwlink? Linkid = 149156 & V = 3.0.40624.0 "style =" text-Decoration: none; ">
</A>
</Object>
Note: When initparams is used to pass parameters, it must be passed in the format of key-value pairs such as X = Y, A = B.
CS section:
App. XAML. CS:
Public partial class app: Application
{
Idictionary <string, string> _ DIC;
...
Private void application_startup (Object sender, startupeventargs E)
{
_ DIC = E. initparams;
This. rootvisual = new mainpage(_ DIC );
}
...
Note: here we use E. initparams to obtain the passed parameters, and use new mainpage (_ DIC) to upload the parameters to the expected XAML.
Mainpage. XAML. CS section:
Public partial class mainpage: usercontrol
{
Idictionary <string, string> _ Params;
Public mainpage ()
{
Initializecomponent ();
}
Public mainpage (idictionary <string, string> dicparam)
{
Initializecomponent ();
_ Params = dicparam;
Stringbuilder sb = new stringbuilder ();
Foreach (VAR item in _ Params)
{
SB. append (string. Format ("key: {0}, value: {1}" + environment. newline, item. Key, item. Value ));
}
Txtparam. Text = sb. tostring ();
}
}
Note: Here, we reload a constructor with parameters to accept parameters.