How to clear whole navigation history hosted by the WPF Frame control

梦想与她 提交于 2021-02-07 06:49:38

问题


In a WPF application the Frame control is used to host/navigate pages. I'd like to clear the navigation history. There is NavigationService.RemoveBackEntry() method which can be used to clear the backward portion of the history. But what about the forward navigation history? How to clear this part? What is the best practice? Thank you in advance.


回答1:


Here's the code I used to clear a Frame's navigation history:

 public void ClearHistory()
 {
     if (!this.Frame.CanGoBack && !this.Frame.CanGoForward)
     {
         return;
     }

     var entry = this.Frame.RemoveBackEntry();
     while (entry != null)
     {
          entry = this.Frame.RemoveBackEntry();
     }

     this.Frame.Navigate(new PageFunction<string>() { RemoveFromJournal = true });
}



回答2:


I didn't try it, But you can try and navigate to the same page and than remove the backpage...



来源:https://stackoverflow.com/questions/8585519/how-to-clear-whole-navigation-history-hosted-by-the-wpf-frame-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!