The Artima Developer Community
Sponsored Link

.NET Buzz Forum
How to pass initialization params to a Silverlight 2 app

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ashish Shetty

Posts: 402
Nickname: nerddawg
Registered: Oct, 2004

Ashish Shetty is a Program Manager at Microsoft.
How to pass initialization params to a Silverlight 2 app Posted: Mar 10, 2008 5:55 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Ashish Shetty.
Original Post: How to pass initialization params to a Silverlight 2 app
Feed Title: Even a chimp can write code
Feed URL: http://nerddawg.blogspot.com/rss.xml
Feed Description: Ideas on software and elsewhere by Ashish Shetty: erstwhile chimp and occasional re-inventor of the wheel.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Ashish Shetty
Latest Posts From Even a chimp can write code

Advertisement

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.

Read: How to pass initialization params to a Silverlight 2 app

Topic: WPF: Performance messen und verbessern Previous Topic   Next Topic Topic: Expression Studio 2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use