h1

Hello,

I'm trying to remove all the pages in my journal from a navigation service.

Code Snippet

while (_navigationService.RemoveBackEntry() != null) ;

The first itration works great. THe second iteration returns null, eventhough there are elements in the _navigationService's back button (Journal).

Is there anotherway I can do this

Or should I just use the frame to clean the back button.

Thanks



Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

Chango V. - MSFT

How can you tell there are still back entries left What happens when you call GoBack() after the loop with RemoveBackEntry() Can you describe your scenario or show some code






Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

h1

When the loop exits on the screen I can see back entries.

Thanks





Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

h1

Hey is there a way I can remove all the entries from the navigation service.

Thanks





Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

Michael.Weinhardt - MSFT

If I run code like this [1] (from an XBAP):

1) There are not entries on the back stack

2) IE7's navigation UI is emptied (ie there are no items in IE7's back navigation list

Do you have more than one navigation service in your app What type of app is it From where are you trying to get the navigaiton service

[1]

public partial class Page3 : System.Windows.Controls.Page

{

public Page3()

{

InitializeComponent();

Button button = new Button();

button.Content = "Remove back entries";

button.Click += new RoutedEventHandler(button_Click);

this.Content = button;

}

void button_Click(object sender, RoutedEventArgs e)

{

// Remove back entries

while (this.NavigationService.RemoveBackEntry() != null) ;

// Count entries on backstack

int i = 0;

foreach (JournalEntry entry in ((NavigationWindow)App.Current.MainWindow).BackStack) i++;

// Display count (note - the message is always "Entries in backstack = 0"

Console.WriteLine("Entries in backstack = " + i.ToString());

}

}





Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

Chango V. - MSFT

Is this NavigationService associated with a Frame or a NavigationWindow If it is for a frame and the frame doesn't have its own journal (controlled via the JournalOwnership property), then RemoveBackEntry() will do nothing. Please describe the setup of your application and what it is doing.




Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

h1

Gentlemen thank you for your help! The application I'm writing is an exe.

I set the JournalOwnership property. I also realized that my loop wasn't in the best place.

So it is working now. Thank you.

One thing I find confusing is that my pages have the KeepAlive="False" property.

My frame also has KeepAlive="False" property.

But still I have to runaround and remove back entries. I confirmed with clr profiler that back entries were actually carring references to actual pages. I was paying for it big time.

I'm navgating like this:

Page1 p = new Page1();

_frame.NavigationService.Navigate(p);

Thanks.





Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

Chango V. - MSFT

Glad to hear you've resolved the problem.

KeepAlive=false is effective only when you navigate to a page by URI. If you navigage "to an object", the framework will keep the page alive. It has no way of knowing where it came from.

The one notable exception is PageFunctions. We have special 'journal by type' support for them. Essentially, a new instance of the PF will be created via reflection. The journal entry only captures enough metadata to do that (and to re-create the Return event handler..).






Re: Windows Presentation Foundation (WPF) NavigationService.RemoveBackEntry

h1

That's great.

Thanks.