Prevent WPF Frame from storing history in the stack

只愿长相守 提交于 2021-02-07 12:31:07

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/2285122/prevent-wpf-frame-from-storing-history-in-the-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!