Navigation of Pages in Windows Store App

Introduction

 
Navigation is one of the important and most used features in any app development because you always need to move (navigate) from one page to another.
 
This article only explains navigation in Windows Store Apps using C#.
 
Our Agenda is
  • Try to implement C# code for navigation.
  • Then try to some "VALUE" along with the navigation

Use the following procedure to create the sample

 
Step 1
 
Get a blank Windows Store C# project and add an extra XAML page.
 
You can do it by the shortcut key (Ctrl+Shift+A).
 
 
Step 2
 
 
Add a button on your MainPage.xaml.
  1. private void Button_Click(object sender, RoutedEventArgs e)    
  2. {    
  3. // Navigate to MyNewPage.xaml    
  4. this.Frame.Navigate(typeof(MyNewPage));    
  5. }    
Now, create the Click event by double-clicking on the Button. 
 
In the same way, in Windows Phone, we have a Navigate() method, but it handles things differently.
 

What if, I want to some value along with this Navigation?

 
For that, we have a solution.
 
You need to a another argument to the navigate() method without any query variable.
  1. private void Button_Click(object sender, RoutedEventArgs e)    
  2. {    
  3. // Navigate to MyNewPage.xaml    
  4. this.Frame.Navigate(typeof(MyNewPage),"Hello Abhishek"); 
  5. }   
We have ed “Hello Abhishek” and in our NavigatedTo page, we try to process it.
 
So, create an onNavigatedTo method in your New Page.
 
And add a TextBox named textBox1.
 
Within that, use the following code.
  1. protected override void OnNavigatedTo(NavigationEventArgs e)    
  2. {    
  3. string myName = e.Parameter as String;    
  4. textBox1.Text = myName;    
  5. }    
And the outcome will be
 
 
After a click.
 
 
 

Conclusion

 
This is one of the most used features of Windows Store Apps.
 
And by ing a query you can send values to the next pages.
 
Regarding this article, if you encounter any issue then try to figure it out from the given solution file.
 
Stay Raw, Stay Geek and Keep Coding.


Similar Articles