top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

+2 votes
70 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 .
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...