Mobile Zone is brought to you in partnership with:

Senthil Kumar is a Software Engineer who has around 3 years of experience in IT industry. He is currently working as a Software Engineer in Bangalore and works mainly on the Windows or Client Development technologies and has good working experience in C#/.NET, Delphi, Winforms and SQL Server. He is also a Microsoft Technology Certified Professional in ASP.NET. He Blogs at http://www.ginktage.com and http://www.windowsphonerocks.com. He enjoys learning as much as he can about all things related to technologies to get a well-rounded exposure of technologies that surround him. Senthil completed his Master of Computer Applications from Christ College (Autonomous), Bangalore in the year 2009 and is a MCA Rank Holder. He has passion for Microsoft technologies especially Windows Phone development. You can connect with him on Twitter at (http://twitter.com/isenthil) , on Facebook at (http://www.facebook.com/kumarbsenthil) and his blog (www.ginktage.com). Senthil is a DZone MVB and is not an employee of DZone and has posted 118 posts at DZone. You can read more from them at their website. View Full User Profile

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

09.03.2012
| 5004 views |
  • submit to reddit

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)
            {
                Window.Current.Activate();
                return;
            }

            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;
            Window.Current.Activate();
}

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, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)