打印

How to pass initialization params to a Silverlight 2 app

http://nerddawg.blogspot.com/2008/03/how-to-pass-initialization-params-to.html
引用:
This is something of an FAQ on our internal discussion lists, so I figured it merited a post.

Step 1: Declare the initParams param on the Silverlight plug-in and pass in a comma-delimited set of key-value pair tokens. For e.g. "key1=value1,key2=value2,key3=value3".
复制内容到剪贴板
代码:
<object type="application/x-silverlight"
        width="100%" height="100%">
  <param name="source"
         value="ClientBin/SLInitParams.xap"/>
<!-- startPage key can have values Page1 or Page2 -->
  <param name="initParams"
         value="startPage=Page1" />
</object>
For best results, the key and value tokens in the initParams string must be restricted to alphanumeric values. There currently isn't support for escaping equality signs or commas, for instance, should they exist in the key or value part of the token.

Step 2: In the Application's Startup event handler, extract the initialization parameters via StartupEventArgs.InitParams property. You'll get an IDictionary<string, string>.

// Contents of App.xaml.cs
复制内容到剪贴板
代码:
private void Application_Startup(object sender,
                                   StartupEventArgs e)
{
    string startPage = e.InitParams["startPage"];
    if (startPage != null && startPage.Equals("Page1"))
    {
       // Load Page1
       this.RootVisual = new Page();
    }
    else
    {
       // Load Page2
       this.RootVisual = new AlternatePage();
    }
}
Simple, huh? I have a sample project on how to pass initialization params to a Silverlight 2 app, and conditionally show UI, up on my sky drive.
Cool~   thanks   
我不知道该不该转帖别人的blog文章, 因为可能都看过了, 只是觉得这个板块关注的人较少, 增加点人气
引用:
原帖由 lbx1979 于 2008-3-11 14:18 发表
我不知道该不该转帖别人的blog文章, 因为可能都看过了, 只是觉得这个板块关注的人较少, 增加点人气
感谢lbx1979对sl板块的支持。
转载注明出处即可。
相信会有更多人关注Silverlight。

[ 本帖最后由 langmuir 于 2008-3-11 15:26 编辑 ]

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!