1. Create a new Windows Phone Application project.
2. In the MainPage.xaml file copy the following xaml into the ContentGrid Grid:
<StackPanel Orientation="Vertical" VerticalAlignment="Center" >
<TextBox Name="ValueTextBox" Width="200" ></TextBox>
<Button Width="200" Height="30" Content="Next Page"Click="Button_Click"></Button>
</StackPanel>
3. Copy the following event handler code to the MainPage.xaml.cs file:
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri(string.Format("/SecondPage.xaml?val={0}", ValueTextBox.Text),UriKind.Relative));
}
4. Add a new Windows Phone Portrait Page to the project named SecondPage.xaml.
5. Paste the following XAML in the ContentGrid Grid in SecondPage.xaml:
<Button Name="GoBackButton" Width="200" Height="30" Content="Go Back" Click="Button_Click"></Button>
6. Copy the following event handler code to the SecondPage.xaml.cs file:
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.GoBack();
}
7. Add the following code to the constructor in SecondPage.xaml.cs:
this.Loaded += new RoutedEventHandler(SecondPage_Loaded);
8. Add the following loaded event handler to the SecondPage.xaml.cs file:
void SecondPage_Loaded(object sender, RoutedEventArgs e)
{
if (NavigationContext.QueryString["val"].Length > 0)
MessageBox.Show(NavigationContext.QueryString["val"], "Data passed",
MessageBoxButton.OK);
else
MessageBox.Show("{Empty}!", "Data Passed",MessageBoxButton.OK);
}
9. Run the application, enter some text in the text box and click on the next page button to see the application in action:
Congratulations! You have created a new Windows Phone 7 application with page navigation.