防止 WPF Frame 在堆栈中存储历史记录 [英] Prevent WPF Frame from storing history in the stack

查看:163
本文介绍了防止 WPF Frame 在堆栈中存储历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的解决方案,但我浪费了太多时间试图解决这个问题.也许我的应用程序设计不正确(可能是这种情况),所以如果您有更好的解决方案,请帮助我.

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.

我正在设计一个企业级 WPF 应用程序,它看起来很像 Outlook,带有 Ribbon 而不是工具栏.当用户单击 RibbonButton 时,我将许多不同的模块加载到框架中.请记住,他的功能区在所有模块中共享.

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.

所以我有一个带有丝带和框架的外壳.当用户单击功能区按钮时,它会将正确的模块(用户控件)加载到框架中.一切都很好.但是,如果我导航到另一个模块(通过单击另一个 RibbonButton),然后单击原始 RibbonButton,我现在打开了同一模块的两个实例......但只有一个显示在框架……另一个模块在框架的堆栈中.

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.

所以我的问题是,当我导航到不同的模块时,如何告诉框架关闭用户控件?我试过设置 JournalEntry.KeepAlive="False",但这仍然不起作用.有什么想法吗?要发布的代码确实不多,但如果对您有帮助,我可以发布.

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.

推荐答案

如果您从不打算返回"到上一个条目,您可以使用 NavigationService.RemoveBackEntry() 以清除每次导航时的历史记录.最简单的方法是处理 Frame 的 导航事件:

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

这篇关于防止 WPF Frame 在堆栈中存储历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆