Tuesday, December 27, 2011

How to Detect Clicking Hardware Back Button

You may usually want to detect clicking hareware back button on MainPage.xaml to exit your app or to resolve some paging problem.

You can detect clicking hareware back button using OnBackKeyPress method like OnNavigatedTo method. Please see bellow sample.

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));

I could pass Marketplace submission using above code.
I use the code in a page in my app because I want that it should be back to MainPage when Back Button is clicked in this page.

No comments:

Post a Comment