Windows phone 7 导航到新页面失败

Windows phone 7 导航到新页面失败,windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,我在windows phone应用程序中有一个页面。在本页中有一些时间。用户可以通过按delete按钮删除此项目。以前,当按back按钮时,用户可以看到已删除的项目,这会导致程序出错。所以我覆盖了后退按钮,停止了它的工作。我在我的应用程序上创建了自己的后退按钮,当用户按下我的应用程序的后退按钮时,它将导航到主页。 我使用了以下代码: protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)

我在windows phone应用程序中有一个页面。在本页中有一些时间。用户可以通过按delete按钮删除此项目。以前,当按back按钮时,用户可以看到已删除的项目,这会导致程序出错。所以我覆盖了后退按钮,停止了它的工作。我在我的应用程序上创建了自己的后退按钮,当用户按下我的应用程序的后退按钮时,它将导航到主页。 我使用了以下代码:

 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));

    }
这可能对你有帮助

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
       // e.Cancel = true; 
         NavigationService.Navigate(new Uri("/MainPage_page.xaml", UriKind.Relative));

    }
您的按钮单击事件似乎正常导航到主页面时没有问题

//看起来还可以

private void button1_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/MainPage_page.xaml", UriKind.Relative));
    }
如果我猜对了,MainPage_page.xaml on navigatedto方法中还有其他一些导航

//查看您的主页\ u page.xaml

protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
更改:

NavigationService.Navigate(new Uri("/MainPage_page.xaml", UriKind.Relative));
致:


当然,除非您已重命名页面。

如果我在OnBackKeyPress中使用导航代码,则错误显示为://如果导航失败,则要执行的代码private void RootFrame_NavigationFailed(对象发送方,NavigationFailedEventArgs e){If(System.Diagnostics.Debugger.IsAttached){//导航失败;进入调试器系统。诊断。调试器。中断();}}查看异常,我建议您检查页面名称“/MainPage_page.xaml”是否为正确路径?如果未找到给定的相对路径,则会发生此异常。
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));