I have lots of pages in my app . When I click back button it does not navigate to previous page but it navigate to the lock screen where all apps are present . Should I have to write code for back button for navigation??
Asked
Active
Viewed 771 times
0
-
Are you targetting Silverlight or WinRT? Are you using NavigationHelper? Have you subscribed to `HardwareButtons.BackPressed`? – Romasz Jul 23 '14 at 18:51
-
WinRT i am just checking the default behaviour. – Ghazanfar Khan Jul 23 '14 at 19:06
-
Can you provide sample code – Ghazanfar Khan Jul 23 '14 at 19:13
-
1What sample code? I thought you can provide some :) Please check your app.xaml.cs for eventhandler `HardwareButtons_BackPressed` also check if you hadn't subscribed somewhere to this event elsewhere, especially please check if you have a folder called `Common` and `NavigationHelper.cs` there. If you don't have them, you can add *Basic Page* to your project and this will add some helper files. – Romasz Jul 23 '14 at 19:16
-
1possible duplicate of [Windows Phone 8.1 Universal App terminates on navigating back from second page?](http://stackoverflow.com/questions/24335925/windows-phone-8-1-universal-app-terminates-on-navigating-back-from-second-page) – Igor Ralic Jul 23 '14 at 21:41
2 Answers
0
Yes you need to override OnBackKeyPress
of the phone to handle where the back button should navigate to.

ΩmegaMan
- 29,542
- 12
- 100
- 122
0
AddHandler HardwareButtons.BackPressed, AddressOf HardwareButtons_BackPressed
Private Sub HardwareButtons_BackPressed(sender As Object, e As BackPressedEventArgs)
e.Handled = True
YourGoBackCode()
End Sub
And same in c#
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
e.Handled = true;
YourGoBackCode();
}

JumpyStackOverflow
- 720
- 5
- 13
-
-
VB should be quite easy to understand and convert to c#. I've always thought that every single c# programmer would be way better at programming languages than us who use VB only. Anyways I'll update the answer with c# aswell. – JumpyStackOverflow Jul 25 '14 at 20:04