Silverlight tutorial: HOW TO Set or change Silverlight startup page or class?

I’ve been struggling for a while with this problem. I had Silverlight project with number of pages that I have designed and later I decided that I want to change to some other page to be the startup page when my projects starts. Solution is quite simple and neat so I wanted to share it with you.

In WPF – it is very simple – especially if you are using Expression Blend 2. You can just right – click on the desired Window or Page in Project tree and from the drop down menu click on “Startup”.

Setting startup page in Expression Blend for WPF

Unfortunately this just won’t work with Silverlight 2 projects – does not matter if you decide to use Blend or Visual Studio. So – to make it work you need to dig into some coding, if I can even dare to call it coding.

Open your Silverlight 2 project in Visual Studio 2008 or Expression Blend 3 (we will need ability to edit some code). Locate the App.xaml file and its code-behind file called App.xaml.cs.

Setting startup page for Silverlight takes some (simple) code hacking

Open the App.xaml.cs file and locate the lines:

private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Load the main control
            this.RootVisual = new PutYourPageClassNameHere();
        }

Replace the PutYourPageClassNameHere with your actual Class name and after you hit F5 again that page / class will be the first one to start.

Pretty simple, isn’t it? Now I just hope that Silverlight guys will make push to get this exposed like it is the case with WPF projects now.

6 Responses to “ Silverlight tutorial: HOW TO Set or change Silverlight startup page or class? ”

  1. Vipul Soni says:

    Thanks! very cool and direct post…

  2. Desika says:

    It worked! thanks a lot!

Trackbacks

  1. Vibor Cipan
  2. Vibor Cipan
  3. Vibor Cipan
  4. Aramail Phone Cards » HOW TO Set Silverlight startup page or class?

Leave a Reply