By Nick Randolph

Nokia Windows Phone: Question 1

By Nick Randolph

We’re running a challenge wherein you can Win a Nokia Windows Phone. The rules of said competition are detailed in the aforelinked post. There will be many more questions over the coming weeks, here is Question 1.

Question 1

Silverlight for Windows Phone has a similar navigation model to Silverlight for the desktop where you have a frame which hosts a series of pages. Unlike on the desktop, where you may have content outside the frame (for example header, footer or perhaps a navigation menu), in most phone applications the frame takes up the entire screen, and subsequently the pages that render within the frame also take up the entire screen. To navigate between pages you can either call the Navigate method on either the frame, or via the NavigationService that is exposed as a property on each page within a Windows Phone application. For example, the following navigates to SecondPage.xaml

this.NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

In addition to being able to navigate forward to a new page, there are many more navigation APIs available to your Windows Phone application. List a navigation API and provide a short example of how you might use it within your application?

  • Caliburn Micro,

    1. Register your viewmodel with CM in the bootstrapper
    protected override void Configure()
    _container = new PhoneContainer(RootFrame);
    2. To navigate call

    • hmm, the comments stripped some code for some reason,
      it should be

      protected override void Configure()
      _container = new PhoneContainer(RootFrame);
      _container.PerRequest ();
      _container.PerRequest ();

      _navigationService.UriFor ().Navigate();

      passing generic type into the PerRequest and UriFor methods

  • Ok so seeming as the comments doesn’t like greater than less than code i created a blog post

  • has a similar strongly-typed navigation helper.

    For example, to navigate to a different page:

    ShowAboutDialogCommand = new DelegateCommand(() => Controller<HomeController>().NavigateTo(c => c.AboutDialog));

    Or you can declare the navigation using attached properties:

    These two examples demonstrate how you might display your About page – that is, the details and contact information about your application – to the user.

    • Oops, missed the second snippet:

      “Or you can declare the navigation using attached properties:

      <Button commands:Navigate.To=”Home.About” Content=”About” />”

  • Clinton Cherry

    Another way could be to simply use a Hyperlink button and enter in the relative Uri of the page you want to navigate to


    • Clinton Cherry

      …and here is the example snippet:

      HyperlinkButton Content=”Go Somewhere” NavigateUri=”/MyNewPage.xaml” /

  • Ryan, Brendan and Clinton – all great answers. I definitely see the value of extending the built in navigation service. Would love to see metrics about the impact on startup time and memory footprint for using frameworks like Caliburn Micro and WindowsPhoneMVC (and more than just on hello world!)

  • Answer:

    Using Search extra’s you have to use the UriMapper to translate abstract Uri’s into uri’s that the navigation service can use. An example:

    The query string can then be extracted from the NavigationContext.QueryString property.

    Regarding perf on WP MVC (I cannot talk for Caliburn as I found the reflection to be a bit heavy) but as far as I can tell, the impact is minimal and most performance problems come from user code, not the framework. I have been working on making it easier to know where perf bottlenecks are in your application, see

    Once the app is started you incurr a cost of about 50ms max for a navigation, but you can pass entire objects between pages and have type safe nav. =)

    MahTweets for Mango starts up with no splash screen and feels far more responsive than v1 and it is using it.

  • Craig Naumann

    I’m looking forward to being able to try something like:

    // AuthenticationCanceled is a bool created from another test – if the user canceled the login
    if (AuthenticationCanceled)
    while (NavigationService.CanGoBack)

    in an app that uses a login page. Not so much for initial usage (logically the login will be done first), but moreso when forcing a re-login after tombstoning for fast app switching.

  • I have a menu system within my game that allows you to go back to the main menu. Which can create a circular navigation stack. To get around this I use the Non Linear Navigation service. This is initialised in the application constructor using the following:


    Then any regular navigate calls are routed through the service. Check out the following for more info:

  • I would call out the this.NavigationService.RemoveBackEntry(); method.

    Calling this from the OnNavigatedTo() of a page will remove the last page from the navigation stack. This affects the behaviour of the back key.

    I use this when I want to redirect the initial page load of an application, say to a login page. This gives the user the expected behaviour of the back button exiting the application, even though they are technically two pages deep.

    It can also be useful if you allow the user to change language or other styles from within the app, you can clear the back stack, then navigate forward to the home page (rather than back from the settings page) which forces a redraw. A bit of a hack, but very simple.

  • Garth Bacon

    You can use the GoBack APi method to go to previous page if available:

    private void btnBack_Click(object sender, RoutedEventArgs e) {
    if (this.NavigationService.CanGoBack)

  • The competition is now closed for entries. The following entries have been recorded. If, for whatever reason, your entry is not in this list, please feel free to respond
    Ryan (2 entries as first answer)
    Brendan Forster
    Clinton Cherry
    Jake Ginnivan
    Craig Naumann
    Daniel Spruce
    Chris Sanity
    Garth Bacon

Get the latest in Mobile, once a week, for free.