Reputation: 244
I created a Windows Phone 8.1 project in which I used the following code in different pats of the code:
if (this.NavigationService.CanGoBack)
{
this.NavigationService.RemoveBackEntry();
}
I tried porting this code to a universal app, and I get an error saying that the NavigationService could not be resolved. How do I handle navigation in the universal app world?
Upvotes: 3
Views: 4940
Reputation: 716
I had the same issue and can't find NavigationSerice either.
But after some searching I found the solution for Navigate, I hope you can use something like this.
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(BasicPage2));
}
See this page for more information.
The BackButton works totaly different on Windows 8.1 you don't need to remove the BackEntry(). But instead you have to add some code when you want to Navigate Back.
For Example:
If you Navigate From Mainpage to Page1 and you want Navigate Back from Page1 to the Mainpage with the (Hardware)BackButton you have te add following to the Mainpage:
Add this inside the constructor:
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
And create this method:
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
if (Frame.CanGoBack)
{
Frame.GoBack();
//Indicate the back button press is handled so the app does not exit
e.Handled = true;
}
}
Now your app navigates back from Page1 to Mainpage using the BackButton.
Upvotes: 7