简体   繁体   English

通用应用程序/ Windows手机,相当于OnBackKeyPressed

[英]Universal App / Windows phone, OnBackKeyPressed equivalent

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. 它是一个通用应用程序,但我首先要制作Windows Phone 8.1。 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' 错误3'Windows.UI.Xaml.Controls.Page'不包含'OnBackKeyPress'的定义

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. 发生错误的原因是Windows应用程序项目中没有OnbackKeyPress的定义。 So you have to define this for the Phone Project only. 因此,您只需要为Phone Project定义它。 Putting the code inside a file that is in the Phone-Project would also work. 将代码放在Phone-Project中的文件中也可以。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM