Over a million developers have joined DZone.

How to: Change the Start Page of a Windows 8 App in Visual Studio 2012

· Mobile Zone

When you create a new Modern UI(Metro) Windows 8 Project in Visual Studio , a default start page MainPage.xaml will be created automatically along with other necessary files needed for running the Windows 8 App.

If you want to change the default start page of the Windows 8 App from MainPage.xaml to another file for example (firstpage.xaml) , you can do that by following the below steps.

The App.xaml.cs has the Onlaunched event where the initial start page is defined . By Default , the MainPage is included .

How to change the Start page of the Windows 8 App in Visual Studio 2012 ?

How to change the Start page of the Windows 8 App in Visual Studio 2012 ?

You can create a new blank xaml page and replace “MainPage” with the newly create page name . For example , if your new pagename is firstpage.xaml , then replace MainPage with the firstpage like the way shown in the below sourcecode sample.

// Invoked when the application is launched normally by the end user.  Other entry points
// will be used when the application is launched to open a specific file, to display
// search results, and so forth.
//Details about the launch request and process.
protected override void OnLaunched(LaunchActivatedEventArgs args)
            // Do not repeat app initialization when already running, just ensure that
            // the window is active
            if (args.PreviousExecutionState == ApplicationExecutionState.Running)

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                //TODO: Load state from previously suspended application

            // Create a Frame to act navigation context and navigate to the first page
            var rootFrame = new Frame();
            if (!rootFrame.Navigate(typeof(firstpage)))
                throw new Exception("Failed to create initial page");

            // Place the frame in the current Window and ensure that it is active
            Window.Current.Content = rootFrame;

Now , run the application . You should see the Application running with the new start page in the Emulator now :)


Published at DZone with permission of Senthil Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}