Displaying multiple silverlight 2 pages on the same HTML page
Last post 04-28-2008 7:26 AM by stewhall. 2 replies.
Sort Posts:
04-27-2008 5:10 PM
Displaying multiple silverlight 2 pages on the same HTML page

Is it possible to display more than 1 silverlight 2 page on a single HTML page?

I have Page1.xaml and Page2.xaml and they both need to be shown at the same time.
I could do this with silverlight 1.1 alpha, but cannot work out how to do this in silverlight 2.

stewhall

Joined on 04-27-2008
Posts 2
04-28-2008 3:26 AM
Marked as Answer
Re: Displaying multiple silverlight 2 pages on the same HTML page

If you want to show the multiple Silverlight controls, there are two options.

Option #1: You can create multiple Silverlight projects and use them in ASP.NET. This is the easiest way to do.

Option #2: If you don't want to create multiple projects then you can use initParams of Silverlight control to pass the parameter from ASP.NET project to Silverlight project.

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!)

Best Regards,
Michael Sync

Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed

mchlSync

Joined on 09-16-2005
Singapore
Posts 2,021
04-28-2008 7:26 AM
Re: Displaying multiple silverlight 2 pages on the same HTML page

Many thanks for your help, that is just what I wanted to do.

Thanks again

Stew.

stewhall

Joined on 04-27-2008
Posts 2