Windows phone 7 阻止根框架上的BackKeyPress无法工作Windows Phone
最近我遇到了另一个我很难理解的问题。在msdn()上,我们看到:Windows phone 7 阻止根框架上的BackKeyPress无法工作Windows Phone,windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,最近我遇到了另一个我很难理解的问题。在msdn()上,我们看到: Also, the BackKeyPress event is available in the PhoneApplicationFrame class. The frame can handle the event directly before the active page receives it and the key press can be canceled 根据这一点,我写了一个简单的例子: private voi
Also, the BackKeyPress event is available in the PhoneApplicationFrame class. The frame can handle the event directly before the active page receives it and the key press can be canceled
根据这一点,我写了一个简单的例子:
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
RootFrame.BackKeyPress += App_BackKeyPress;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
void App_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
Debug.WriteLine("1");
e.Cancel = true;
}
在MainClass中,我在下面添加了代码,以确定它是否真的停止了
public MainPage()
{
InitializeComponent();
this.BackKeyPress += MainPage_BackKeyPress;
}
void MainPage_BackKeyPress(object sender, CancelEventArgs e)
{
Debug.WriteLine("2");
}
令我失望的是,输出显示“1 2”,那么有什么不对?它没有抑制按键执行吗?我遇到了类似的问题,Windows Phone只能在有东西要返回时取消返回执行,我指的是任何PhoneApplicationPage。我猜你们在你们的第一页上按了返回按钮,所以WP并没有什么可备份的。在您的页面上,添加指向另一页面的按钮,然后在此页面上按“返回”以确定执行是否被抑制 如果在
void主页上按BackKeyPress(对象发送者,CancelEventArgs e)
将:if(!e.handled)Debug.WriteLine(“2”)代码>?e.Handled不存在,而不是此:)-如果(!e.Cancel)Debug.WriteLine(“2”),则应为代码>不显示任何内容,例如,取消设置为false。我删除了我的答案,因为它原来是无用的。除了答案之外,你在下面的评论也被删除了(没有答案,它们也将是无用的和误导性的)。