DarksideCookie

Come to the dark side...we have cookies!

InitParams...a good way to start

A feature that is often missed in Silvelright is the possibility to give the application information at start up. Sort of like sending parameters to a constructor. This is done by passing values through the InitParams property. This feature has been available since Silverlight 1.0, but it has changed in 2.0. A 2.0 application is split in two parts, an Application class and a UserControl, and the InitParams is sent to the Application part. If you listen to the Application.Startup event, you will get hold of an StartupEventArgs object. This control contains a InitParams property containing the values sent to the control. The InitParams is a comma separated string when added in markup, but a IDictionary<string,string> when in code. How you pass it from the Application object to the UserControl is up to the developer. There are several ways of doing this. The simplest is to add a parameter to the contructor of the UserControl and pass in the Dictionary there. Another is to add a property on the Application class and "publish" the information there and let the UserControl fetch it.

This parameter is available to us if we use the <asp:Silverlight /> control. This makes it a very simple way for us to pass a certain amount of data from serverside aspx code to our clientside Silverlight application without having to use Ajax or webservices. Or maybe we could use the InitParams to tell our application the Uri to the webservice...

Posted: Jul 07 2008, 18:24 by ZeroKoll | Comments (0) |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Silverlight
Manage post: :)
Comments are closed