微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

向silverlight传递自定义参数

 在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" />                        <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>      

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐