All silverlight controls are zipped into a single .xap file. And the
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/MySLapp.xap" />The App.xaml file contains the Application_Startup event which contains the information about the starting user control which will be rendered when the silverlight xaml is consumed by the browser. We can manipulate the InitParams property of this method to dynamically set the starting user control for the silverlight application. The below method shows how can we achieve the requirement of calling different user controls from the same aspx page.
Firstly set the different user controls on the aspx page as shown below
<asp:Silverlight ID="Xaml1" InitParameters="ControlId=1" runat="server" Source="~/ClientBin/MySLapp.xap" />Next, you can dynamically set the user control to be rendered by the application using this logic
<asp:Silverlight ID="Xaml2" InitParameters="ControlId=2" runat="server" Source="~/ClientBin/MySLapp.xap" />
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.InitParams.ContainsKey("ControlId"))
{
if (e.InitParams["ControlId"] == "1" )
this.RootVisual = new UserControl1();
else
this.RootVisual = new UserControl2();
}
}
where UserControl1 and UserControl are you Silverlight UserControls.
Technorati Tags: application_startup silverlight,dynamically set user controls on the page,host multiple silverlight controls,InitParams
del.icio.us Tags: application_startup silverlight,dynamically set user controls on the page,host multiple silverlight controls,InitParams
2 comments:
that was exactly what i needed, thanks!
Thanks for this post.
I m looking this kind of article last 2 days n finally i found it.
Thanks again.
Post a Comment