Usman ur Rehman Ahmed's blog

Basic Navigation between pages in Windows Phone 7 Application

Right click on your first Windows Phone 7 Project and select Add > New Item,

Choose the page of your desired type (I have added the portrait page). Now move to the MainPage design surface and place a button as well as a Hyperlink Button control. These are two most commong navigation controls that you would normally use.

Navigation
As shown in the figure above, the hyperlink button provides a property named NavigateUri that allows you to navigate between pages without raising an event. This property is not available in the Button control meaning by the only way to perform navigation from Button control is by means of coding for the event _Click. Please also note that the Click event is equally available in the Hyperlink Button control.

To perform navigation you will have to specify the complete name of the page (with .xaml extension) prefixed by a forward slash as shown above. This convention is equally followed if navigation is performed using the event in code behind. Using code behind, you will have to use either fo the following static methods of the NavigationService class (the class itself is available as a property of the application),

- GoBack (Before using this method, check if going back is ppssible using boolean property CanGoBack)

- GoForward (Before using this method, check if going forward is possible using boolean property CanGoForward)

- Navigate

The use of Navigate method is shown below,

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Page1.xaml",UriKind.Relative));
        }

In the next post I will speak of NavigationContext and NavigationCacheMode properties.

11
To Posterous, Love Metalab