【问题标题】:navigating to same page in windows phone 8在 Windows Phone 8 中导航到同一页面
【发布时间】:2013-04-01 20:26:49
【问题描述】:

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

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

当用户按下后退键应该返回到“MainPage.xaml”页面。

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

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

【问题讨论】:

  • 你能在 PostBack URL 中传递# 登录吗?

标签: c# navigation windows-phone-8


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    使用NavigationService.RemoveBackEntry 方法删除最后一个导航堆栈条目。

    您还可以从导航历史记录中删除所有元素:

    while(service.CanGoBack)
        service.RemoveBackEntry();
    

    然后添加你感兴趣的那个。

    【讨论】:

      【解决方案3】:
      NavigationService.Navigate(new Uri("/MainPage.xaml?" + DateTime.Now.Ticks, UriKind.Relative));
      

      您可以在控件下使用它来导航到同一页面

      【讨论】:

        【解决方案4】:

        因为我找不到任何有关此问题的 Windows 10(通用应用程序 UWP UAP)问题,而且这个问题似乎是谷歌搜索重新加载页面的最佳结果,这里有一个解决方案:

        NavigationService.Refresh();
        

        我在我的应用程序上使用Template 10,所以我不知道这是否重要。该库将 NavigationService 封装在自己的 INavigationService 上

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-10-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多