Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Can a silverlight application find it's parent?
3 replies. Latest Post by BrianMinister on May 5, 2008.
(0)
BrianMin...
Member
6 points
5 Posts
05-05-2008 7:44 PM |
I am using the Silverlight ASP.NET control to host my silverlight application.
I have several instances of the same silverlight application running and I am looking for a way for my application to know which element instance it is being hosted in, so I can have the Silverlight control react to the right HTML tag.
mchlsync
Star
14606 points
2,730 Posts
05-05-2008 9:33 PM |
You can use initParams of asp:Silverlight control to pass the parameters to Silverlight.
05-05-2008 9:35 PM |
For example:
Let's say we have one asp:Silverlight control in two content pages.
Content1 (aspx)
<asp:Silverlight ID="Silverlight1" InitParameters="PageId=1" runat="server" Height="100px" Width="100px"> </asp:Silverlight>
Content1 (html)
<div id="silverlightControlHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%"> <param name="source" value="RichText.xap"/> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="initParams" value="PageId=1" /> <a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </object> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div>
Content2 (aspx)
<asp:Silverlight ID="Silverlight1" InitParameters="PageId=2" runat="server" Height="100px" Width="100px"> </asp:Silverlight>
Content2 (html)
<div id="silverlightControlHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%"> <param name="source" value="RichText.xap"/> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="initParams" value="PageId=2" /> <a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </object> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div>
App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e){ int pageID = int.Parse(e.InitParams["PageId"]); if(pageID == 1){ this.RootVisual = new Page1();
} else{
this.RootVisual = new Page2(); }
05-05-2008 10:06 PM |
That is exactly what I was looking for!
If it works, then this will rock!