views:

26

answers:

1

Hi,

If i have two aspx pages in each of them i want to put differents silverlight contents (2 differents usercontol) what can i do?.. am i obliged to add 2 silverlight projects with my asp.net website and insert in each page an *.xap content..?

Thanks.

+2  A: 

No you can put both UserControls in a single XAP if you prefer.

You would use the initParams to choose which to display when the app is loaded.

Here is an example approach I've use in the past:-

private void Application_Startup(object sender, StartupEventArgs e)
{
  string pageName = "UserControl1";

  if (e.InitParams.ContainsKey("startPage"))
  {
     pageName = e.InitParams["startPage"];
  }

  Type pageType = Assembly.GetExecutingAssembly().GetType("SilverlightApplication1." + pageName);
  RootVisual = (UIElement)Activator.CreateInstance(pageType);

}

Your object tag param list would look like:-

<param name="source" value="ClientBin/SilverlightApplication1.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="startPage=UserControl2" />

When you have a new Silverlight user control to add you just add it to the existing SL project and then you can use it by copying any existing object tag markup and tweaking the startPage.

Beware loading up a XAP too much else small changes you can increase the download costs for your users where a separate XAP for each may not have incurred such a cost.

AnthonyWJones