Setting start page of Windows Phone dynamically through code

时间:2024-12-08 18:06:20

Essentially this one line of code will set the start page of the application.

 var navTo = new Uri("/Views/MainPage.xaml", UriKind.RelativeOrAbsolute);
((App)Current).RootFrame.Navigate(navTo);

Then you will have to set start page in App.Xaml.cs as below.

 private void Application_Launching(object sender, LaunchingEventArgs e)
{ }

Last thing you need to do is remove entry of default task from WMAppManifest.xml file. If you notice entry for default navigation page is empty.

  <Tasks>
<DefaultTask Name ="_default" NavigationPage=""/>
</Tasks>
<Tokens>
<PrimaryToken TokenID="liveTilesToken" TaskName="_default">
<TemplateType5>
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
<Count>0</Count>
<Title>liveTiles</Title>
</TemplateType5>
</PrimaryToken>
</Tokens>