tags:

views:

306

answers:

1

When you create a Silverlight app using:

<asp:Silverlight id="SlApp" runat="server" Source="~/ClientBin/SLApp.xap" MinimumVersion="2.0" />

is there a way to pass in custom information (like a string) so that it can be accessed inside the Silverlight app's C# code? Like inside the Silverlight's App() constructor?

Thanks,

Jeff

+4  A: 

When using the Silverlight ASP.NET web control, there is an 'InitParameters' property that you can use to pass in initialization parameters as key/value pairs...

<asp:Silverlight id="SlApp" runat="server" Source="~/ClientBin/SLApp.xap" MinimumVersion="2.0" InitParameters="id=12345,name=john" />

Then in your Silverlight application, you can read those properties in the application's Startup event...

public partial class App : Application
{
 public App()
 {
  Startup += Application_Startup;
 }

 private void Application_Startup(object sender, StartupEventArgs e)
 {
  string id = e.InitParams["id"];
  string name = e.InitParams["name"];
 }
}

The InitParameters property of the StartupEventArgs is simply a generic IDictionary<string,string>.

John Clayton