使用 PRISM 处理导航的最佳方法是什么?

发布于 2024-08-24 15:29:36 字数 257 浏览 5 评论 0原文

使用 Prism - 在 WPF 应用程序中处理导航的最佳方法是什么?你如何应用这个?有没有最佳实践?

在我的应用程序中,我当前正在使用事件聚合。任何应导致程序中导航的菜单项或其他项都将发布事件,并且负责打开由已发布事件表示的视图的模块将执行此操作。这工作得很好,但我有一种感觉,这不是使用 Prism 处理导航的最佳方式。是吗?

Using Prism - what is the best way to handle navigation in a WPF application? And how do you apply this? Are there any best practices?

In my application I'm currently using Event Aggregation. Any menu item or other item that should result in navigation in the program will publish an event, and the module responsible for opening the view represented by the published event will do so. This works just fine, but I have a feeling this is not the best way to handle navigation with Prism. Is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-08-31 15:29:36

它和其他方法一样好,至少就 Prism 而言是这样。我以前做过的一种方法是将一个模块/类设置为“导航代理”;对于MDI类型的应用程序,由于缺乏创意,我通常将其称为WindowManager。这个人将被注入 IRegionManager 和 IEventAggregator 并开始侦听任何“新窗口”或“导航到”类型的事件并适当地更改/创建区域。如果您想变得更聪明,可以开始使用作用域 RegionManager:

http:// /msdn.microsoft.com/en-us/library/cc707903.aspx

http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how- to-build-an-outlook-style-application-with-prism-v2-part-2.aspx

这种策略(以及一般使用事件聚合方面)的主要问题是,您需要的任何 CompositePresentationEvents由多个模块或至少在引发模块“外部”处理,您需要在公共位置声明(我通常将它们放在名为基础设施的项目中)。这个我不太喜欢。

It's as good a method as any other, at least where Prism is concerned. One way I've done it before is to set up one Module/Class as your "Navigation broker"; for MDI type applications, I usually call it WindowManager due to lack of creativity. This guy will get injected with the IRegionManager and the IEventAggregator and start listening for any "New Window" or "Navigate To" type of events and alter/create regions appropriately. If you want to get slightly clever, you can start using scoped RegionManagers:

http://msdn.microsoft.com/en-us/library/cc707903.aspx

http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx

The main problem with this tactic (and using the event aggregation aspects in general) is that any CompositePresentationEvents you need to handle by multiple modules or at least "outside" of the raising module, you need to have declared in a common location (I usually put them in a project called Infrastructure). This I am not overly fond of.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文