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();

Published by

Tim Clark

Experienced Business Owner, Chief Information Officer, Vice President, Chief Software Architect, Application Architect, Project Manager, Software Developer, Senior Web Developer, Graphic Designer & 3D Modeler, University Instructor, University Program Chair, Academic Director. Specialties: Ruby, Ruby on Rails, JavaScript, JQuery, AJAX, Node.js, React.js, Angular.js, MySQL, PostgreSQL, MongoDB, SQL Server, Responsive Design, HTML5, XHTML, CSS3, C#,, Project Management, System Design/Architecture, Web Design, Web Development, Adobe CS6 (Photoshop, Illustrator)

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 )

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