Tags

Silverlight does not have the Page type, the term is currently used is RootVisual UserControl. RootVisual object is analogous to the root window in WPF and can only be set once for the lifetime of the app, and is effective once the Application’s Startup event is raised. But this not true, you can set RootVisual as many times you want. So Application_Startup can be used to call multiple Silverlight controls.

Create a Silverlight application in visual studio 2008
Add 3 new Silverlight controls and lets name them Header, Footer and Leftbar.
Now put some text in these controls so that they can be distinguished on the aspx page.

Call these control s in the Form of Testpageforsilverlightapplication and set the InitParameters.

Change the Application_Startup in App.xaml.cs as below.

private void Application_Startup(object sender, StartupEventArgs e)

{

if (e.InitParams.ContainsKey(“ControlId”))

{

switch (e.InitParams[“ControlId”])

{

case “Header”:

this.RootVisual = new Header();

break;

case “Leftbar”:

this.RootVisual = new Leftbar();

break;

case “Footer”:

this.RootVisual = new Footer();

break;

}

}

}

Run the application and all the 3 controls can be seen on aspx page. If we put a breakpoint at Application_Startup and we can see that it is called as many times as there silverlight controls on aspx page.

Advertisements