0

is there any way to handle the Windows button keypress within the *.Xaml.cs especially when the app is busy getting a request processed using an Asynchronous BeginGetResponse. is there a override handler like OnBackKeyPress?

What's the appropriate way to handle this use case? i'm already handling Application_Activated and deactivated in the App.Xaml.cs file for tombstoning.

Jay Kannan
  • 1,372
  • 3
  • 14
  • 30

1 Answers1

1

You can't stop this from happening. When this happens the current page will get its OnNavigatedFrom override called so you could clean up your page and save state from this method.

Bear in mind that it won't be possible to tell whether this is due to the hardware Start key or if the user just navigated away by say pressing the Back key or tapping a button.

Update:

If you're trying to avoid a crash due to Fast App Switching interrupting your networking call you should rather handle this when you return to the application. Your WebRequest will be cancelled and you should handle this case as shown in this MSDN blog post.

Paul Annetts
  • 9,554
  • 1
  • 27
  • 43
  • OnBackKeyPress can tell if it's the back key. I don't want to stop the Windows key from functioning, but just abort the webrequest so that the user can try again after return. at the moment it returns to an error. – Jay Kannan Jan 26 '12 at 15:56
  • To be honest it's not worth canceling when leaving the page (that'll be done for you automatically). However when you are returning to the page you should handle the fact that your WebRequest was cancelled. – Paul Annetts Jan 26 '12 at 16:05
  • makes sense, will try it out. – Jay Kannan Jan 26 '12 at 18:10