拼吾爱程序人生

首页 » .Net编程 » Silverlight » 向silverlight传递自定义参数
cobra - 2008-4-9 8:33:00
文/nasa  出处/博客园

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

ok 获取参数完成 ;)

附录:获取客户机ip  "System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString();"

 您可能对 [Silverlight] 的这些文章也感兴趣:

什么是SilverLight
走近Silverlight
四个原因让Silverlight无法取代Flash
Silverlight、JavaFX、Flex/Flash技术比较
Silverlight vs Flash的技术比较
Silverlight:你需要知道的十件事情
在Silverlight中使用定时器(Timer)
Silverlight应用程序的.NET项目结构
设计silverlight的MediaPlay控件
设计一个silverlight的Button控件补完设计
.NET开发Silverlight程序:界面和对象模型
Halo 3网站显示出SilverLight的缺陷
1
查看完整版本: 向silverlight传递自定义参数
Modify by pin5i DZNT_ExpandPackage 2.1.3295 2007-2009 pin5i.com
 Total Unique Visitors: