【问题标题】:How do i navigate backward and refresh the page i have navigated to?如何向后导航并刷新已导航到的页面?
【发布时间】:2014-07-08 08:02:40
【问题描述】:

我正在使用 App.RootFrame.GoBack();但它不会刷新页面(这是有道理的)。

我想强制刷新页面...无论如何要这样做?

【问题讨论】:

    标签: c# windows-phone-8


    【解决方案1】:

    this 可能重复。

    无论如何,您可能希望按如下方式使用 NavigationService:

    if(NavigationService.CanGoBack())
    {
        NavigationService.GoBack();
    }
    
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        // ensure view has the data it needs
    }
    

    【讨论】:

      【解决方案2】:

      这似乎做得很好。

      IEnumerable<JournalEntry> pages = App.RootFrame.BackStack;
      string pageURL = pages.First().Source.OriginalString;
      App.RootFrame.Navigate(new Uri(pageURL + "?Refresh=true&random=" + Guid.NewGuid(), UriKind.RelativeOrAbsolute));
      

      【讨论】:

      • 那么你必须在新页面的OnNavigatedTo中调用两次PhoneApplicationFrame.RemoveBackEntry()以获得“刷新”效果。
      • 谢谢,是的,我确实这样做了......虽然我确信这不是最好的技术......我会在以后重新访问它......因为它运行良好 atm!
      【解决方案3】:

      在“GoBack()”上,将运行 OnNavigatedTo() 方法,但不会运行页面的构造函数。因此需要在 OnNavigatedTo() 方法中自己刷新页面。

      protected override void OnNavigatedTo(NavigationEventArgs e)
      {
          // Refresh the data in here
      }
      

      我还怀疑你最好使用导航服务返回,即:

      NavigationService.GoBack();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多