在 Windows Phone 8 中导航到同一页面 [英] navigating to same page in windows phone 8

查看:18
本文介绍了在 Windows Phone 8 中导航到同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WP8 应用程序中,我必须从一个页面导航到另一个页面,然后由于某些原因我需要重新加载同一页面.

In my WP8 app, i have situation where i have to navigate from one page to another and afterwards i need to reload the same page for some reasons.

MainPage.xaml --> Page1.xaml --> Page1.xaml --> Page1.xaml

MainPage.xaml --> Page1.xaml --> Page1.xaml --> Page1.xaml

当用户按下返回键时应该返回MainPage.xaml"页面.

When user press the backkey should go back to "MainPage.xaml" page.

我尝试使用 NavigationService.navigate() 进行导航,但由于某些原因我无法重新加载页面.如果我通过导航 url 传递任何唯一的查询字符串(例如:Guid),我就可以重新加载页面.但是,当我按下后退按钮时 - 它永远不会返回 Mainpage.xaml 页面.

I tried using the NavigationService.navigate() for navigation, some reason i couldn't able to reload the page. If i pass any unique query strings (eg: Guid) with navigation url, i am able to reload the page. But, when i press back button - it never goes back to Mainpage.xaml page.

有没有最好的方法来实现这一目标?

Is there any best way to achieve this?

推荐答案

每次重新加载页面时传入一个查询字符串(例如随机 GUID).在您的 OnNavigatedTo 方法上检查 GUID 查询字符串是否存在.如果它确实存在,您知道您不希望在 Navigation Stack 上显示此页面,因为它是重新加载的版本,因此您可以通过调用 NavigationService.RemoveBackEntry.

Pass in a query string every time you reload the page (such as your random GUID). On your OnNavigatedTo method check if the GUID query string exists. If it does exist, you know that you don't want this page on the Navigation Stack because it's the reloaded version, so you can remove it by calling NavigationService.RemoveBackEntry.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string guid = string.Empty;
    if (NavigationContext.QueryString.TryGetValue("guid", out guid))
    {
       //guid exists therefore it's a reload, so delete the last entry
       //from the navigation stack
       if(NavigationService.CanGoBack)
          NavigationService.RemoveBackEntry();
    }
}

这篇关于在 Windows Phone 8 中导航到同一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆