In Windows Phone 7, is there a way to know if the back is pressed in the page that's navigated to? I know we can intercept in the current page but I need to know in the page I am navigating to. i.e. if there 2 pages say page1 and page2, back button is pressed in page2. I need to know if back button is pressed or not in page1. I need to run some stuff on back button press in page1.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
...
}
This is kind of a hack but you can do the following; override OnBackkeyPress
event on every page. Within the event handler add the following code:
PhoneApplicationService.Current.State["isbacknav"] = true;
Then, in the OnNavigatedTo
event handler for every page, check whether the State
dictionary contains that entry.
bool isbacknav = false;
if( PhoneApplicationService.Current.State.ContainsKey( "isbacknav" ) ) {
isbacknav = (bool)PhoneApplicationService.Current.State["isbacknav"];
PhoneApplicationService.Current.State["isbacknav"] = false;
// or
// PhoneApplicationService.Current.State.Remove( "isbacknav" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With