none
How add two xaml to aspx page

    Question

  • Hello everyone ,

    I am new in silverlight and I know how to add 1 object of silverlight which is from mainpage.xaml to aspx pages but for example if I have another xaml like mypage.xaml and I want to add both xaml to the page what should I do?

    Please help me

    Tuesday, February 01, 2011 1:48 AM

Answers

  • Sorry, I had misspelling in my last post.  Should be:

    <param name="initParams" value="Page=Page1"/>

    Friday, February 04, 2011 12:43 PM

All replies

  • Below is the SilverLight host which is added to the .aspx file. If you want two just copy paste twice and change the names to load two SL host. But dont ask abt communicating between two its tedious.

     <div id="silverlightControlHost">
            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
        <param name="source" value="ClientBin/SLForum.xap"/>
        <param name="onError" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="4.0.50826.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
        </a>
         </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

     
    Tuesday, February 01, 2011 3:08 AM
  • Thanks for your quick reply:

    But when I copy the object how can I refrence to my second xaml page because in the project there is only one xap which I should refrence to it ?

    please help me

    Wednesday, February 02, 2011 1:18 AM
  • <param name="source" value="ClientBin/<application>.xap" />

    You can copy the .xap files to your ClientBin directory and link it here.

    You can right click on the .Web project go to the Silverlight Application tab and there you can add the silverlight project which will auto copy the xap file.

     

    Wednesday, February 02, 2011 1:51 AM
  • Hi alt_fo ,

    In truth ,I have added 2 object and copied my .xap as you said and refrence the second object to the copy of xap as follow but my xap and its copy refrence to the same xaml file and my problem is how can I refrece the copy of xap to for example second.xaml file which is different from mainpage.xaml file and my code looks like this:

    <div id ="silverlightControlHost">

    <object data="data:application/x-silverlight-2,"

    type="application/x-silverlight-2" style="height: 200px; width : 33%">

    <param name="source" value

    ="ClientBin/animation.xap"/>

    <param name="onError" value="onSilverlightError"

    />

    <param name="background" value="white"

    />

    <param name="minRuntimeVersion" value="4.0.50826.0"

    />

    <param name="autoUpgrade" value="true"

    />

    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration

    :none">

    <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style

    :none"/>

    </a

    >

    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe

    >

    <object data="data:application/x-silverlight-2,"

    type="application/x-silverlight-2" style="height: 200px; width

    : 33%">

    <param name="source" value

    ="ClientBin/Copy of animation.xap"/>

    <param name="onError" value="onSilverlightError"

    />

    <param name="background" value="white"

    />

    <param name="minRuntimeVersion" value="4.0.50826.0"

    />

    <param name="autoUpgrade" value="true"

    />

    <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration

    :none">

    <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style

    :none"/>

    </a

    >

    </object></div

    >

    <iframe id="Iframe1" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe

    >

    </div

    >

     

     

     

     

     

    Wednesday, February 02, 2011 12:05 PM
  • This may not be the easiest/best way, but if it was me, I would just compile the 2nd xap with the 2nd xaml file before uploading it. So, in other words, each xap file would be compiled separately according to which xaml file you want each to use.

    Wednesday, February 02, 2011 2:01 PM
  • Thanks Will,

    For a moment I make 2 project and compile 2 .xap then congeregate them into 1 asp.net project as like as you but it does not stands to reason and it takes long !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Friday, February 04, 2011 10:33 AM
  • Let us know how it works out!  Maybe if someone else knows of a better way they'll chime in...

    Friday, February 04, 2011 10:46 AM
  • I am new in silverlight and I know how to add 1 object of silverlight which is from mainpage.xaml to aspx pages but for example if I have another xaml like mypage.xaml and I want to add both xaml to the page what should I do?

    You can have one Silverlight application project (one xap file).  Assume it contains two UserControls Page1.xaml and Page2.xaml, and you want Page1 to be shown in Silverlight Control1, and Page2 to be shown in Silverlight Control2 in the same aspx page.

    You can use initParams in the Silverlight control tag to indicate which UserControl you want to use as the application start up page:

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
              <param name="source" value="ClientBin/YOURAPP.xap"/>

               <param name="initParams" value="Page=Page1"/>

              ...

    </object>

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
              <param name="source" value="ClientBin/YOURAPP.xap"/>

               <param name="initParams" value="Page=Page2"/>

              ...

    </object>

    Code in App.xaml Application_Startup:

    private void Application_Startup(object sender, StartupEventArgs e)
            {
               
                if(e.InitParams.ContainsKey["Page"])

                {           

                     string page = e.InitParams["Page"];

                     if(page == "Page1")

                         this.RootVisual = new Page1();

                     if(page == "Page2")

                         this.RootVisual = new Page2();

                }

             }

    Friday, February 04, 2011 11:10 AM
  • Hi sally,

       I tried, it works for me. I now know there is a initparams property

    Friday, February 04, 2011 11:29 AM
  • Great solution!!!

    Friday, February 04, 2011 11:31 AM
  • Hi sladapter,

    First thanks for your reply I have tested your code but there is a problem with this line(please look at the error message too)

    if (e.InitParams.ContainsKey["Page" ])

    and the error messege is as follow:

    Cannot apply indexing with [] to an expression of type 'method group'

     

     

     

    Friday, February 04, 2011 11:58 AM
  • For more explanation ,

    I have changed ["page"] to ("page") and the error was solved but in this case the if statement return always false and the

    code below cannot be executed

    string page = e.InitParams["Page"];

                     if(page == "Page1")

                         this.RootVisual = new Page1();

                     if(page == "Page2")

                         this.RootVisual = new Page2();

    Friday, February 04, 2011 12:31 PM
  • Sorry, I had misspelling in my last post.  Should be:

    <param name="initParams" value="Page=Page1"/>

    Friday, February 04, 2011 12:43 PM
  • It works you have solved the question of many people thanks.

    Friday, February 04, 2011 1:03 PM
  • Thanks Sally, it works Great.

    Just That

     replaced if(e.InitParams.ContainsKey["Page"]) with

    if (e.InitParams.ContainsKey("Page"))

    Friday, April 20, 2012 6:06 AM