Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

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 :)

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}