Thursday, March 08, 2012

Set start page dynamically in wp7

My new Windows Phone 7 app "WeekCal" provides different calendar views. There are actually two week views and a month view. In the settings, the user can set the view to start with.
To start the app with the view the user has choosen, there are two steps necessary.

First step is to select the right view in the App.xaml.cs file and set it as root frame element. Do this in the Application_Launching method. Here is an example:

 private void Application_Launching(object sender, LaunchingEventArgs e)
   Uri uri;
   // Read the user settings
   var views = IsolatedStorageProvider.LoadViewSettings();
   // Month view
   if (views.ShowMonthView)
     uri = new Uri("/MonthViewPage.xaml", UriKind.Relative);
     // Week view
     if (views.ShowFiveDaysWeek)
       uri = new Uri("/FiveDaysPage.xaml", UriKind.Relative);
       uri = new Uri("/SevenDaysPage.xaml", UriKind.Relative);
   // Set the start page

Everything looks ok, but the app does not start with the right view. There is one more easy step to do. In the WMAppManifest.xml file, the DefaultTask tag needs an empty NavigationPage property. So just delete the default entry MainPage.xaml.

 <!--This is set in code (App.xaml.cs)-->
 <DefaultTask Name="_default" NavigationPage="" />

That's it, hope that helps.


raghav rocking said...

How to get the ColorPickerPage.xaml for windows phone 7 ???

Jean-Claude Trachsel said...

Sorry, but I don't get the question. Can you please let me know, how I can help you.

Nick Adams said...

Thanks to you share with me this nice blog.So keep it up..