Silverlight: Passing InitParams to your Application from the Page

To pass initialization parameters (InitParams) to your Silverlight application at its startup you can simply add a new  ‘initParams’ element to the Silverlight Object markup within your page. The ‘initParams’ element contains for its value a hash of key value pairs you wish to pass into the application in the for “key=value”.

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="ClientBin/JoxStrap.Silverlight.Home.xap"/>
    <param name="onError" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="3.0.40624.0" />
    <param name="autoUpgrade" value="true" />
    <param name="initParams" value="baseUri=" />
    <a href="" style="text-decoration:none">
      <img src="" alt="Get Microsoft Silverlight" style="border-style:none"/>
     </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

After adding the ‘initParam’ element to the object markup you then read in these parameters in the Application_Startup method located in your App.xaml.cs file.

private void Application_Startup(object sender, StartupEventArgs e)
            StartUpParameters startup = StartUpParameters.Instance;

                string uriString = e.InitParams["baseUri"];
                if (!string.IsNullOrEmpty(uriString))
                    Uri baseUri = new Uri(uriString);
                    startup.BaseUri = baseUri;
                startup.BaseUri = null;

            RootVisual = new MainPage();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s