Reputation: 295
I've created a frame with a few pages. The frame has its own journal:
JournalOwnership="OwnsJournal"
When I pass 2 pages, I want to clean the frame NavigationService
:
Frame parent_frame = (Frame)Application.Current.MainWindow.FindName("content_frame");
JournalEntry remove = parent_frame.RemoveBackEntry();
while (parent_frame.NavigationService.CanGoBack) {
parent_frame.NavigationService.RemoveBackEntry();
MessageBox.Show("Remove");
}
But after cleaning NavigationService
I can go back.
Upvotes: 0
Views: 478
Reputation: 169
The easiest way to do that is to handle the frame Navigated event:
frame.Navigated += frame_Navigated;
void frame_Navigated(object sender, NavigationEventArgs e)
{
frame.NavigationService.RemoveBackEntry();
}
Upvotes: 1
Reputation: 295
I've removed all possible pages in NavigationService.BackStack
and added event when I remove the last page.
Frame root = (Frame)Application.Current.MainWindow.FindName("content_frame");
int i = 0;
while (root.NavigationService.CanGoBack) {
i++;
root.NavigationService.RemoveBackEntry();
}
root.NavigationService.RemoveBackEntry();
MessageBox.Show("Deleted - " + i);
NavigatedEventHandler navigated_handle = null;
navigated_handle = (o, e) => {
((Frame)o).RemoveBackEntry();
MessageBox.Show("Do and remove itself!");
root.Navigated -= navigated_handle;
};
root.Navigated += navigated_handle;
Upvotes: 0