How does Silverlight/xap receive parameters?

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.