Tutorials » Silverlight tutorials »

How to set default .xaml page in a Silverlight control ?

This chapter demonstrates how to change the default .xaml page used in a Silverlight control

Each Silverlight project can have multiple .xaml files. However, only one .xaml file will be visible at a time.

When you create a Silverlight project in Visual Studio, it will create a .xaml file called "Page1.xaml" by default and this .xaml control will be displayed by default when you open the web page.

You can change the default .xaml page by setting the property "Application.RootVisual".

To try this, add a .xaml file called "Page2.xaml" in your silverlight project.

Now, open your App.xaml.cs file in the Silverlight project. Look at the Application_Startup event handler. There you can see the default .xaml page being set. To change the default .xaml page, you have to specify the name of the class used in the .xaml page and set it to the Application.RootVisual property as shown below:

private void Application_Startup(object sender, StartupEventArgs e)
this.RootVisual = new Page2();

After you change the value here, compile the application and run. When the web page is opened, you can see that the new .xaml control is displayed in the web page.

Next Chapter: How to open XAML pages from another XAML page ?
Previous Chapter: How to place a Silverlight control in a web page ?
More Chapters: Silverlight Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India