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.
Now, create the Click event by double-clickiing on the Button.
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- this.Frame.Navigate(typeof(MyNewPage));
- }
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.
- private void Button_Click(object sender, RoutedEventArgs e)
- {
-
- this.Frame.Navigate(typeof(MyNewPage),"Hello Abhishek"); }
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:
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- string myName = e.Parameter as String;
- textBox1.Text = myName;
- }
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.