Silverlight技术调查(1)——Html向Silverlight传参

来源:互联网 发布:玉溪餐饮软件yxqlkj 编辑:程序博客网 时间:2024/04/30 23:06

近几日项目研究一个很牛的富文档编辑器DXperience RichEdit组件,调查环境为Silverlight4.0,应用服务器为Tomcat6.20,组件版本为11.1,因为项目此需求已被终止,将一些心得及部分成果(与项目无关的)公开,希望对需要的同仁有帮助。

只写具体结果,相关参考大家可以在网上查相关资源,比如Silverlight基础、MSDN、DXperience官网、或其它相关资源,不再赘述。


关键参数:initParams,参数以逗号分隔,若需传逗号需要自行编码(MSDN如是说)。

HTML代码:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">  <param name="source" value="RichEdit.xap"/>  <param name="onError" value="onSilverlightError" />  <param name="background" value="white" />  <param name="minRuntimeVersion" value="4.0.50826.0" />  <param name="autoUpgrade" value="true" />  <param name="culture" value="ja" />  <param name="uiculture" value="ja" />  <param name="initParams" value="arg0=第一个参数,arg1=第二个参数" />  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">   <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>  </a>    </object>

Silverlight代码-将参数放入Resources中-App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)        {            if (e.InitParams != null)            {                foreach (var item in e.InitParams)                {                    this.Resources.Add(item.Key, item.Value);                }            }             this.RootVisual = new MainPage();        }
Silverlight代码-根据Key取相应参数-MainPage.xaml.cs:

private string GetParam(string p)        {            if (App.Current.Resources[p] != null)            {                return App.Current.Resources[p].ToString();            }            else            {                return string.Empty;            }        }