Reputation: 3768
I have "MainPage" and "FriendsPage".How I can simulate the back button if user clicked the back button in "FrinedPage".MaiPage can show only one time.
MainPage>Friendspage, no returning back .
I think I need to use "OnNavigatedFrom" method, but I don't know how.Please help me.
Upvotes: 2
Views: 1560
Reputation: 25156
There's probably a way to get what you want without violating the requirements.
what is on your "mainpage" that you don't want the user to go back to? from your limited info, it sounds like the mainpage shouldn't be your "main" page then.
You probably want your friendspage to be the main page, and have a popup or something that includes whatever you would have had on your "mainpage".
for other non-standard situations, there are some exceptions to the navigation rules, see the "nonlinear navigation" stuff: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/12/13/solving-circular-navigation-in-windows-phone-silverlight-applications.aspx
Upvotes: 0
Reputation: 986
Unlike WPF, one is not allowed to drop pages from the backstack in a Windows Phone app. Also there is certification requirement that from the first page of the app (assuming MainPage.xaml), the user should be able to hit "Back" & exit the app. So, please consider carefully what you are trying do.
That said, there are couple of ways:
Override & eat up OnBackKeyPress: This might lead to a jarring user experience though.
Override OnNavigatedTo() in MainPage and throw an unhandled exception to exit app or take other appropriate action (NavigationService.GoBack() or some other page). There was a nice post about exiting a SL app (here). Also, if using GoBack(), keep in mind that you are now taking over some responsibility to maintain the backstack after the jump; might have to be done consistently throughout the app.
Hope this helps!
Upvotes: 0
Reputation: 1720
On a button click call
NavigationService.GoBack();
or, in VB.NET,
NavigationService.GoBack()
Here is the MSDN docs: http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.goback.aspx
Upvotes: 4
Reputation: 1092
You should be able to handle/Override OnBackKeyPress and set cancel = true to prevent moving backwards in your app.
Upvotes: 0