Alex Martianov
Alex Martianov

Reputation: 81

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

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.

Upvotes: 8

Views: 13672

Answers (2)

Flatliner DOA
Flatliner DOA

Reputation: 6327

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 });
}

Upvotes: 14

Eyal Wurmbrand
Eyal Wurmbrand

Reputation: 119

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

Upvotes: -2

Related Questions