向silverlight传递自定义参数

简介: 在silverlight往往还是有一些获取不到的东西,比如说客户机的ip等的数据.可以通过初始化sl时把参数传入sl中. 1.修改page类public Page(string passText) {     InitializeComponent();     txtPass.
在silverlight往往还是有一些获取不到的东西,比如说客户机的ip等的数据.可以通过初始化sl时把参数传入sl中.

1.修改page类
public Page(string passText)
{
    InitializeComponent();
    txtPass.Text = passText;
}
2.修改App.xaml.cs
  private   void  Application_Startup( object  sender, StartupEventArgs e)
        {
            
//  Load the main control
             string  passText  =  e.InitParams[ " passText " ];
            
this .RootVisual  =   new  Page(passText);
        }
3.传递参数
  • 方法1:
    Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
        TagPrefix
    ="asp" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        
    <title>passtxt</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
            
    <asp:ScriptManager ID="ScriptManager1" runat="server">
            
    </asp:ScriptManager>
            
    <div style="height: 100%;">
                
    <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/HowTo.xap" Version="2.0"
                    Width
    ="100%" Height="100%"/>
            
    </div>
        
    </div>
        
    </form>
    </body>
    </html>
         protected   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"   />
                
                
    < 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;
}
参数间用","隔开
< 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
相关文章
Silverlight自定义数据绑定控件应该如何处理IEditableObject和IEditableCollectionView对象
原文:Silverlight自定义数据绑定控件应该如何处理IEditableObject和IEditableCollectionView对象 原创文章,如需转载,请注明出处。   最近在一直研究Silverlight下的数据绑定控件,发现有这样两个接口IEditableObject 和IEditableCollectionView,记录一下结论,欢迎交流指正。
838 0
|
JavaScript 前端开发 搜索推荐

热门文章

最新文章