Sunday, January 11, 2015

Overview

In mobile apps, we often navigate to different pages. In this post, we will see how to do that on the windows phone. More information can be found here.

Details

We will have MainPage which will have a button whos click event takes us to a new page, Page2.

MainPage xaml will have a button that will take you to the next page.

1
  <Button Content="Go to Page2" onClick="Button_Click" />

The click event for that button will look like this.

1
2
3
4
// MainPage
private void Button_Click(object sender, RoutedEventArgs e) {
  Frame.Navigate(typeof(Page2), "This is extra data that I'm sending to Page2");
}

On Page2, we can get the parameters passed when we changed pages in the OnNavigatedTo method.

1
2
3
4
// Page2
protected override void OnNavigatedTo(NavigationEventArgs e) {
  Console.WriteLine( e.Parameter.ToString() );
}

Random Posts