top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Windows phone application hardware back button click function not trigger??

+2 votes
86 views

so as of now when a back (hardware) button is clicked it closes the app. How can I work around this so it goes to the previous webpage or goes back to the index or something on those lines?

posted Nov 13, 2014 by Puhal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

Use This method:

   protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
       {

        //Do your work here

        e.Cancel = true;

        var result = MessageBox.Show("Do you want to exit?", "Attention!",
                                   MessageBoxButton.OKCancel);

        if (result == MessageBoxResult.OK)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            return;
        }
        e.Cancel = true;

       // base.OnBackKeyPress(e);
    }
answer Nov 17, 2014 by Jdk
also it works fine, write CanrevertState() as below:

bool CanRevertState()
{
Navigate.GoBack();
return true;
}
and call this CamRevertState() where you need , it just navigate to previous page you visited even when you touch phone's hardware button .
...