Skip to main content

Microsoft Silverlight

Answered Question Can a silverlight application find it's parent?RSS Feed

(0)

BrianMinister
BrianMin...

Member

Member

6 points

5 Posts

Can a silverlight application find it's parent?

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.

初めは容易である-継続は堅い。
Beginning is easy - Continuing is hard.
http://BriansCodeExtreme.blogspot.com

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Can a silverlight application find it's parent?

 You can use initParams of asp:Silverlight control to pass the parameters to Silverlight.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Can a silverlight application find it's parent?

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();
  }

 
}

 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


BrianMinister
BrianMin...

Member

Member

6 points

5 Posts

Re: Can a silverlight application find it's parent?

That is exactly what I was looking for!

If it works, then this will rock!

初めは容易である-継続は堅い。
Beginning is easy - Continuing is hard.
http://BriansCodeExtreme.blogspot.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities