向silverlight传递自定义参数
在silverlight往往还是有一些获取不到的东西,比如说客户机的ip等的数据.可以通过初始化sl时把参数传入sl中.
1.修改page类
ok 获取参数完成 ;)
附录:获取客户机ip "System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString();"
作者:nasa
出处:nasa.cnblogs.com
联系:nasa_wz@hotmail.com
QQ:12446006
1.修改page类
public Page(string passText)
{
InitializeComponent();
txtPass.Text = passText;
}
2.修改App.xaml.cs{
InitializeComponent();
txtPass.Text = passText;
}
private void Application_Startup(object sender, StartupEventArgs e)
{
// Load the main control
string passText = e.InitParams["passText"];
this.RootVisual = new Page(passText);
}
3.传递参数{
// Load the main control
string passText = e.InitParams["passText"];
this.RootVisual = new Page(passText);
}
- 方法1:
Codeprotected void Page_Load(object sender, EventArgs e)
{
Xaml1.InitParameters = "passText=参数_方法1";
} - 方法2:
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" InitParameters="passText=123" width="100%" height="100%">
<param name="InitParams" value="passText=参数_方法2" />
<param name="source" value="ClientBin/HowTo.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
public Page(string passText1,string passText2)
{
InitializeComponent();
txtPass1.Text = passText1;
txtPass2.Text = passText2;
}
参数间用","隔开{
InitializeComponent();
txtPass1.Text = passText1;
txtPass2.Text = passText2;
}
<param name="InitParams" value="passText1=参数1,passText2=参数2" />
ok 获取参数完成 ;)
附录:获取客户机ip "System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString();"
作者:nasa
出处:nasa.cnblogs.com
联系:nasa_wz@hotmail.com
QQ:12446006