.NET Zone is brought to you in partnership with:

Michael Crump is a Microsoft MVP, INETA Community Champion, and an author of several .NET Framework eBooks. He speaks at a variety of conferences and has written dozens of articles on .NET development. He currently works at Telerik with a focus on our XAML control suite.
You can visit his blog at: MichaelCrump.Net or follow him on Twitter at: @mbcrump

Michael is a DZone MVB and is not an employee of DZone and has posted 100 posts at DZone. You can read more from them at their website. View Full User Profile

How to Specify the Startup Page in Windows Phone

05.21.2013
| 1426 views |
  • submit to reddit

Introduction

Something that I get quite often is how do you specify the startup page in Windows Phone. Most people are trying to use the MVVM pattern and by default the MainPage.xaml lives in the root folder as shown below:

image

Most MVVM purist wants this folder to be clean, and only have the App.xaml and App.xaml.cs left. All of the Views should be located in the Views folder.

(You can move the LocalizedStrings.cs to a helper class)

How to do it?

I’ve found the easiest way to do is by deleting the MainPage.xaml file from the root of your project and adding it back to your Views (Add-New Item-Phone-Windows Phone Portrait Page). Then going to your WMAppManifest.xaml file found in Properties and changing the Navigation Page as shown below:

image

If you simply drag and drop the MainPage.xaml file, you will need to fix your x:Class in MainPage.xaml to point to the new location. So, in this case the project is named PhoneAppMVVM it would go from:

x:Class="PhoneAppMVVM.MainPage"

to

x:Class="PhoneAppMVVM.Views.MainPage"

and the MainPage.xaml.cs file would need to be modified from:

namespace PhoneAppMVVM

to

namespace PhoneAppMVVM.Views

Now we have a nicely structured MVVM application that is easy to find what you are looking for fast! The final project solution should look like the following:

image 

Wrap-up

I hope this helped and until next time, Michael signing off.

Published at DZone with permission of Michael Crump, 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.)