Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent WPF Frame from storing history in the stack

This seems like it would be an easy solution, but I'm wasting too much time trying to figure this out. Perhaps I am designing my application incorrectly (which might be the case), so please help me out if you have a better solution.

I'm designing an enterprise level WPF application that looks a lot like Outlook with a Ribbon instead of a toolbar. I have a lot of different modules that are loaded into a frame when the user clicks on a RibbonButton. Keep in mind that his ribbon is shared accross all modules.

So I have a shell with a ribbon and a frame. When the user clicks on the Ribbon button, it loads the proper module (usercontrol) into the frame. All is good. However, if I navigate to another module (by clicking on another RibbonButton), and then click on the original RibbonButton, I now have two instances of the same module open... but only one is shown in the frame... the other module is in the frame's stack.

So my question is, how to I tell the frame to close the usercontrol when I navigate to a different module? I've tried setting the JournalEntry.KeepAlive="False", but that still did not work. Any thoughts? There is really not much code to post, but I can do so if it will help you.

like image 887
Brent Avatar asked Feb 17 '10 23:02

Brent


1 Answers

If you never intend on going "back" to the previous entry, you can use NavigationService.RemoveBackEntry() to clear out the history each time you navigate. The easiest way to do that is to handle the Frame's Navigated event:

frame.Navigated += frame_Navigated;

void frame_Navigated(object sender, NavigationEventArgs e)
{
    frame.NavigationService.RemoveBackEntry();
}
like image 184
Matt Hamilton Avatar answered Oct 19 '22 19:10

Matt Hamilton