C# 控制我的Windows Phone 8.1 Silverlight应用程序的后退按钮

C# 控制我的Windows Phone 8.1 Silverlight应用程序的后退按钮,c#,silverlight,windows-phone-8,back-button,C#,Silverlight,Windows Phone 8,Back Button,我正在开发一个Windows Phone 8.1 Silverlight应用程序。在我的应用程序中,我需要覆盖后退按钮代码 所以我试过这个 protected override void OnBackKeyPress(CancelEventArgs e) { //Navigating to this page when back button is pressed DisplayPage mynewPage = new DisplayPage();

我正在开发一个Windows Phone 8.1 Silverlight应用程序。在我的应用程序中,我需要覆盖后退按钮代码

所以我试过这个

protected override void OnBackKeyPress(CancelEventArgs e)
    {
        //Navigating to this page when back button is pressed
        DisplayPage mynewPage = new DisplayPage();
        this.Content = mynewPage;

        e.Cancel = true;
    }
但是这个代码不起作用。我做错了什么?请帮帮我

编辑:


当我把这个代码放在主页上时,它就工作了!但我不想把它放在那里。我想把它放在其他页面上。

删除“e.Cancel=true”(它会取消导航)。只需导航到新页面即可

编辑:

为了导航到另一个页面,我建议使用NavigationService。查看示例

编辑:

代码段:

    protected override void OnBackKeyPress(CancelEventArgs e)
    {
        //Navigating to this page when back button is pressed
        NavigationService.Navigate(new Uri("/DisplayPage.xaml", UriKind.Relative));

    }

@Shahriarsirisrajsingdho你是这样尝试的吗?受保护的覆盖void OnBackKeyPress(CancelEventArgs e){NavigationService.Navigate(新Uri(“/DisplayPage.xaml”,UriKind.Relative));}这对我来说一直有效。不!不行!每当我按下后退按钮,应用程序就会关闭。我认为重写back按钮的方法在某种程度上是不正确的,当我把这段代码放在主页上时,它工作了!但我不想把它放在那里。我想把它放在其他页面上。这很奇怪,应该在其他页面上也这样做。你的页面看起来怎么样?