C# 通用应用程序/Windows phone,按OnBackKeyPressed等效键
我试图让后退按钮返回到上一页,而不是关闭应用程序。直到现在,我都没有运气。这是一个通用的应用程序,但我首先要做的是windows phone 8.1。我有以下代码,但它不工作C# 通用应用程序/Windows phone,按OnBackKeyPressed等效键,c#,win-universal-app,onbackpressed,C#,Win Universal App,Onbackpressed,我试图让后退按钮返回到上一页,而不是关闭应用程序。直到现在,我都没有运气。这是一个通用的应用程序,但我首先要做的是windows phone 8.1。我有以下代码,但它不工作 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { this.Frame.Navigate(typeof(MainPage)); base.OnBackKeyPress(e); } 这是我得到的
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
this.Frame.Navigate(typeof(MainPage));
base.OnBackKeyPress(e);
}
这是我得到的错误:
错误3“Windows.UI.Xaml.Controls.Page”不包含定义
对于“OnBackKeyPress”
如果代码在共享文件夹中,请尝试将代码放入其中
#if WINDOWS_PHONE_APP
protected override void OnBackKeyPressed(...)
...
#endif
发生此错误是因为Windows应用程序项目中没有OnbackKeyPress的定义。因此,您必须仅为电话项目定义此项。将代码放入电话项目中的文件中也会起作用
希望有帮助有很多信息可供参考