Configure different XAML page as start page using single XAP

1 01 2010

Suppose you have a Silverlight application with 2 page

1) AnimationPage1.xaml

2) AnimationPage2.xaml

And suppose in your Web project you have 2 page

1) TestPage1.aspx

2) TestPage2.aspx

Now you want to use same xap on both .aspx  page but with different animation (different xaml page)

Ok

You can use the initParams property of <object> tag that host Silverlight App:

TestPage1.aspx:

        <object data="data:application/x-silverlight-2,"
            type="application/x-silverlight-2"
            width="100%" height="100%">
            <param name="source" value="../ClientBin/Sample.xap" />
            <param name="initParams" value="startPage=AnimationPage1" />
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="3.0.40624.0" />
            <param name="autoUpgrade" value="true" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0"
            style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
            </a>
        </object>

TestPage2.aspx:

        <object data="data:application/x-silverlight-2,"
            type="application/x-silverlight-2"
            width="100%" height="100%">
            <param name="source" value="../ClientBin/Sample.xap" />
            <param name="initParams" value="startPage=AnimationPage2" />
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="3.0.40624.0" />
            <param name="autoUpgrade" value="true" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0"
            style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
            </a>
        </object>

Now in Silverlight application open the App.xaml

Modify the code like below:

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (e.InitParams.ContainsKey("startPage"))
            {
                if (e.InitParams["startPage"] == "AnimationPage1")
                {
                    this.RootVisual = new AnimationPage1();
                }
                else if (e.InitParams["startPage"] == "AnimationPage2")
                {
                    this.RootVisual = new AnimationPage2();
                }
                else
                {
                    // Assign any default page
                }
            }
            else
            {
                // Assign any default page
            }
        }
Advertisements

Actions

Information

4 responses

13 06 2010
az

thanks. very useful.

30 06 2010
babu

Thanks for the post. I started Silverlight new. I struggled to figure out how to include the xaml in a fresh asp.net page. Your article gave a very good picture of it.

15 09 2010
Harshada

Thank you for the very good post

31 12 2010
Preetham

Thank you for your post, it helped me a lot…..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: