经典论坛's Archiver

lbx1979 发表于 2008-3-11 09:25

How to pass initialization params to a Silverlight 2 app

http://nerddawg.blogspot.com/2008/03/how-to-pass-initialization-params-to.html

[quote]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".
[code]
<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>
[/code]
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
[code]
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();
    }
}
[/code]
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.[/quote]

nasawz 发表于 2008-3-11 10:06

Cool~   thanks   :cool:

lbx1979 发表于 2008-3-11 14:18

我不知道该不该转帖别人的blog文章, 因为可能都看过了, 只是觉得这个板块关注的人较少, 增加点人气:)

langmuir 发表于 2008-3-11 15:21

[quote]原帖由 [i]lbx1979[/i] 于 2008-3-11 14:18 发表 [url=http://bbs.blueidea.com/redirect.php?goto=findpost&pid=3887010&ptid=2836501][img]http://bbs.blueidea.com/images/common/back.gif[/img][/url]
我不知道该不该转帖别人的blog文章, 因为可能都看过了, 只是觉得这个板块关注的人较少, 增加点人气:) [/quote]

感谢[b]lbx1979[/b]对sl板块的支持。:)
转载注明出处即可。
相信会有更多人关注Silverlight。:rolleyes:

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

页: [1]



Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.