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

传递多个参数也是一样的.定义的时候改一下.后边的方法也类似.

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传递自定义参数相关推荐

  1. Ant Design Vue 组件@chang绑定方法如何传递自定义参数

    Ant Design Vue 组件@chang绑定方法如何传递自定义参数 今天在写代码的时候遇到一个问题: 在嵌套标签中 外层使用了一个v-for循环去循环一个数组,当内层想要拿取index,并且使用 ...

  2. 给alias的命令传递自定义参数

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! alia ...

  3. iview on-row-dblclick参数存在多个的情况下传递自定义参数

    @on-row-dblclick="editRow(arguments,index)" 当前行的数据 index 2.如果参数是一个 test($event,自定义参数)

  4. scarpy框架如何在crawl中正确传递自定义参数,scrapy.cmdline的execute为什么不能在while True中无限循环,execute换成crawl 方法

    问题:scrapy.cmdline的execute函数执行完毕为什么一定会停,不能执行后面函数,也不在while True中无限循环(解决问题的结果 在最后) 我想让scrapy程序全年无休止运行,2 ...

  5. element-ui组件中的input等的change事件中传递自定义参数

    以select为例,如果select写在循环里,触发change事件时可能不只需要传递被选中项的值,还要传递index过去,来改变同一循环中的其他标签的状态. 下面这样写是无效的: @change=& ...

  6. Python scrapy 动态传入自定义参数

    本文仅供学习交流使用,如侵立删!demo下载见文末 动态传递自定义参数启动 def run(model_id):# 启动爬虫 car_images_spider是爬虫脚本文件名:spiders/car ...

  7. pyqt5讲解12:自定义参数 (给信号传入参数)

    在pyqt编程过程中,经常会遇到给槽函数传递自定义参数的情况,比如有一个信号与槽函数的连接是 button1.clicked.connect(shou_page) 对于clicked 信号来说,是没有 ...

  8. plupload怎么设置属性_Plupload设置自定义参数

    在HTML 5比较流行的当下,Plupload是文件上传的不二之选,特别是Adobe宣布2020年将停止对Flash的更新支持.本文记录一下如何在上传文件的时候,传递自定义参数. 了解到两种方式,一种 ...

  9. Vue中使用Axios传递数组参数给SpringBoot后台时的实现方式

    场景 在前端需要实现多选,然后将所选的序号的数组传递到后台Springboot接口 需要传递的参数是一个int数组. handleCompleted() {if (this.ids == null | ...

最新文章

  1. 深度拷贝 java_Java深度拷贝方式和性能对比
  2. idea中没有j2ee_idea神器功能大全
  3. 《塔木德智慧全书》(之四)
  4. oracle acfs snap 恢复,删除ACFS系统碰到的问题
  5. java avi转mp4_视频转GIF很麻烦?不!只需三步
  6. python中or是什么意思-Python 中 (,|)和(and,or)之间的区别
  7. 分解gif图片并保存
  8. 使用PowerShell查看Windows 补丁记录并写入数据库
  9. UIAlertView、UIActionSheet兼容iOS8
  10. 你曾后悔进入 IT 行业吗?
  11. 读《天才在左,疯子在右》
  12. 大话Ajax,详解~
  13. vscode Android调试
  14. 【weblogic】WTC配置(Weblogic Tuxedo Connector)
  15. python查找文字在图片中的位置_如何快速提取出图片中文字,强烈推荐这款免费软件!...
  16. Java+selenium简单实现web自动化测试
  17. CANN训练营第三季_昇腾CANN算子精讲课_TBE算子Sinh开发笔记_算子开发(二)
  18. centos linux开机启动项,Centos 配置开机启动项
  19. 一个桔子功效等同五味药
  20. 目前大数据技术平台有很多,主要可以分为哪几类?

热门文章

  1. 关于ShopEx的二次开发的目录结构及各文件功能
  2. 小程序图片在安卓上拉伸的问题导航返回首页
  3. 使用WeexSDK,网络请求信任证书的问题
  4. 结对-贪吃蛇-测试过程
  5. VIJOS【1234】口袋的天空
  6. 微信开发 网页授权获取用户基本信息
  7. 利用dispatch_once创建单例
  8. 编写你自己的单点登录(SSO)服务(转)
  9. 在ASP.NET页面中动态添加控件
  10. Angular2-关闭占用的4200端口