How to: Change the Start Page of a Windows 8 App in Visual Studio 2012
Join the DZone community and get the full member experience.
Join For Freewhen 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 .
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, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments