Windows Phone 8.1 - Page Navigation
Solution 1
In Windows Phone 8.1, Page Navigation method is like this:
Frame.Navigate(typeof(SecondPage), param);
It means that you will navagate to 'SecondPage', and pass 'param' (a class based on object).
If you needn't to pass any parameters, You can use this:
Frame.Navigate(typeof(SecondPage));
You can find the documentation for this MSDN link
Solution 2
In case you want to go back you can use:
if(this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
If you want to go back on the click of back button, you need to override the hardwarebutton event:
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if(rootFrame != null && rootFrame.CanGoBack)
{
rootFrame.GoBack();
e.Handled = true;
}
}
Make sure to set e.Handled to true.
Solution 3
// Navigation Without parameters
this.Frame.Navigate(typeof(SecondPage));
// Navigation with parameters
this.Frame.Navigate(typeof(SecondPage),MyParameters);
Ahmed.C
I am a Windows Phone Guy! well.. I ask you for help more than you ask me :)
Updated on November 10, 2020Comments
-
Ahmed.C over 3 years
Coming from
Windows Phone 8
I have never thought there will be a lot of changes done to theWindows Phone 8.1
code. Basically I'm just wondering how to do page navigation just like how you would do it onWindows Phone 8
. To do that you should add:NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
but that code doesn't work for
Windows Phone 8.1
.Can someone please help me with this? If possible provide any links or documentation on all the new
Windows Phone 8.1
methods. -
Ahmed.C about 10 yearsAnd If I want to go back, clicking the hardware back button doesn't work so would I have to add the hardware back button pressed event and then enter the page which I want? or is their an easier way?
-
Chris Shao about 10 yearsYou can use NavigationHelper in your SecondPage, so that you don't need to add event handler.For example, you can create a BasicPage instead of BlankPage as your SecondPage. And you will see it.
-
Chris Shao over 9 yearswp8.1 is different from wp8.0, but more similar with winrt.
-
Cabuxa.Mapache over 9 years...and don´t forget you can do it at app level: stackoverflow.com/questions/24335925/…
-
Devi Prasad about 9 yearsHow to pass Multiple Paraeters
-
Devi Prasad about 9 yearsHow To pass multiple Parameters.
-
Abdullah El-Menawy about 9 yearsUse array or List<object> , put your parameters in it, and pass the array or the List<object> in the parameter. Do you want a sample ?
-
Chris Shao about 9 years@Devi Prasad You should define a class which contains your multiple parameters.
-
Ishara Amarasekera over 8 yearsThis method worked for me in forward navigation. I added it to the click event in xmal.cs file.