I will start with saying , this post is small and sweet J I was working and come across a requirement to set start page of Windows Phone Application through code or dynamically.

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

image

Say, you have a page called Page1.xaml and you want to set it as start page of application. Then you will have to set start page in App.Xaml.cs as below.


    private void Application_Launching(object sender, LaunchingEventArgs e)
        {

                Uri nUri = new Uri("/Page1.xaml", UriKind.Relative);
                ((App)Application.Current).RootFrame.Navigate(nUri);

        }

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>

This was all about setting the start page in Windows Phone application. I hope this quick post was useful. Thanks for reading Smile

Advertisements

2 thoughts on “Setting start page of Windows Phone dynamically through code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s