开发者

Prevent WPF Frame from storing history in the stack

开发者 https://www.devze.com 2022-12-20 17:28 出处:网络
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 ou

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.KeepAl开发者_如何转开发ive="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.


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

精彩评论

暂无评论...
验证码 换一张
取 消