我在Windows Phone应用程序中有一个页面。在这个页面有一些时间。用户可以通过按下删除按钮来删除这些项目。以前,当按下后退按钮时,用户可能会看到已删除的项目,并导致程序出错。所以我重写后退按钮,并停止它的作品。我在我的应用上创建了自己的后退按钮,当用户按下我应用的后退按钮时,它将导航到主页面。 我用这个代码:导航到新页面失败
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; //Cancels the default behavior.
}
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage_page.xaml", UriKind.Relative));
}
但导航主页无法正常工作。我该如何解决这个问题?
是否有可能通过按下手机的返回键这样的导航到主页:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; //Cancels the default behavior.
NavigationService.Navigate(new Uri("/MainPage_page.xaml", UriKind.Relative));
}
如果我在OnBackKeyPress使用导航代码则错误显示了在该://代码以如果导航失败 私人无效RootFrame_NavigationFailed(对象发件人,NavigationFailedEventArgs E) { 如果(System.Diagnostics.Debugger.IsAttached执行) { //导航失败;打入调试器 System.Diagnostics.Debugger.Break(); } } – DarkenShooter
寻找异常,我会建议你检查你的页面名称,是“/MainPage_page.xaml”的正确路径吗?当找不到相对路径时,会发生此异常。 – Jaihind