0

I am trying to get the back button to go back to the previous page instead of closing the app. Until now, I had no luck. Its a universal app but I'm making the windows phone 8.1 first. I have the following code but its not working!

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
    this.Frame.Navigate(typeof(MainPage));
    base.OnBackKeyPress(e);
}

this is the error I get:

Error 3 'Windows.UI.Xaml.Controls.Page' does not contain a definition for 'OnBackKeyPress'

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Hunt3R
  • 117
  • 3
  • 13
  • There is lot of information available [here...](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn639128.aspx) – Mangesh Nov 16 '14 at 15:29

1 Answers1

0

if the code is inside the shared folder, try put the code inside

#if WINDOWS_PHONE_APP
protected override void OnBackKeyPressed(...)
...
#endif

The error occurs because there is no definition for OnbackKeyPress in the Windows-App-Project. So you have to define this for the Phone Project only. Putting the code inside a file that is in the Phone-Project would also work.

Hope it helps

Jmie
  • 97
  • 1
  • 12