棱镜有帮助吗?
我正在考虑使用 PRISM(复合 WPF 指导/库)构建应用程序。 应用程序模块将被垂直划分(即客户、供应商、销售订单等)。 这仍然相对容易...我还有一个带有主区域的 Shell,所有工作都会发生,但现在我需要以下行为:我的主 Shell 上需要一个菜单,当每个选项被单击时(例如客户、供应商等)我需要找到该模块并将其加载到该区域(一次只有 1 个视图)?
有人知道有这种行为的示例应用程序吗? 所有示例都更注重将所有模块加载到主 shell 上? 我的菜单栏也应该是一个模块吗?
[更新] 如何根据从菜单中选择的模块将模块注入到区域中? 所有示例都表明模块在初始化时将视图注入到该区域中? 如果在菜单上选择了模块,我只需要注入视图?
I am considering building a application using PRISM (Composite WPF Guidance/Library). The application modules will be vertically partitioned (i.e. Customers, Suppliers, Sales Orders, etc). This is still all relatively easy... I also have a Shell with a main region were all the work will happen but now I need the following behavior: I need a menu on my main Shell and when each one of the options gets clicked (like customers, suppliers, etc) I need to find the module and load it into the region (Only 1 view at a time)?
Does anybody know of any sample applications with this type of behavior? All the samples are more focused on having all the modules loaded on the main shell? And should my menu bar also be a module?
[UPDATE] How do I inject a module into a region based on it being selected from a menu? All the examples show that the module injects the view into the region on initialize? I need to only inject the view if the module is selected on a menu?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,PRISM 将为您提供帮助。
这里有很多事情值得一提。
您可以按需加载模块。 PRISM 具有在运行时加载模块的功能,因此在您的情况下,如果您使用 Shell 和 ModuleA 启动上述解决方案。 然后,您的用户触发一个事件(即菜单选择),然后它可以允许您动态加载 ModuleB 并将其注入到播放中。 不过要明确的是,您确实需要坐下来在这里做功课,因为您需要确保 ModuleB 对其他模块等没有任何自己的依赖项(通常使用基础设施模块是明智的。我已经使用了一些技术我在 XML 中查找模块清单,其中列出了其绝对依赖项,然后我确保首先加载它们,然后加载 ModuleB)。
请参阅通过 PRISM 帮助文档(开发活动)按需加载模块。 另请查找准备远程下载模块
通过菜单将视图注入区域是访问 IRegionManager 然后添加它的简单情况。 为此,请确保在您正在使用的所述 ViewModel/Presenter/Controller 的构造函数中:
与 PRISM 一样,您几乎可以将任何您想要的对象添加到您的构造中,并且 PRISM 将确保它按时且按预算到达那里(呵呵)。
从那里开始,您将采用添加视图的正常方法...例如:
所有内容都应该放在一起! :)
注意:
Scott Barnes - 丰富平台产品经理 - Microsoft。
Yes PRISM will help you out here.
A number of things here worth mentioning.
You can load a Module on Demand. PRISM has the capabilities of loading a module at RunTime, so in your case if you bootup the said solution using Shell and ModuleA. Your user then triggers an event (ie Menu choice) it can then allow you to dynamically load ModuleB and then inject that into play. To be clear though, you really need to sit down and do your homework here as you need to ensure ModuleB doesn't have any of its own dependencies on other modules etc (typically its wise to use an Infrastructure Module. I've used techniques where i have a manifest of modules that i lookup in XML that lists its absolute dependencies and then I make sure they are loaded first, then I load ModuleB).
See Load Modules on Demand via PRISM help docs (Development Activities). Also lookup Prepare a Module for Remote Downloading
To inject a View into a Region via Menu is a simple case of accessing the IRegionManager and then adding it. To do this, make sure in your Constructor for the said ViewModel/Presenter/Controller you're using put:
As with PRISM you can pretty much add any object you want into your construct and PRISM will ensure it arrives there on time and on budget (hehe).
From there its the normal approach you'd take with adding a view... eg:
And all should come together! :)
Note:
Scott Barnes - Rich Platforms Product Manager - Microsoft.
刚刚在 dnrTV 观看Brian Noyes on Prism。 这回答了我所有的问题...
Just finished watching Brian Noyes on Prism at dnrTV. This answered all my question...
目前尚不清楚你所说的“找到模块并将其加载到该区域”是什么意思。 您可以加载模块的视图并将其添加到 shell 中。 Composite UI 应用程序块和 CompositeWPF 构建在 IoC 模式之上。 这意味着您的模块应该将其菜单项注入 shell 的菜单条中或订阅 shell 生成的事件。
It's not clear what you mean saying "find the module and load it into the region". You can load module's view and add it to shell. Composite UI app block and CompositeWPF are built on top of the IoC pattern. It means that your modules should inject their menu items in shell's menu strip or subscribe to events generated by shell.
您可以将主要区域设置为 ContentControl,这样一次只有 1 个视图处于活动状态。
您还可以“按需”加载模块。 有一个快速入门可以向您展示如何执行此操作。 您还应该记住,如果模块已经初始化过一次,则第二次初始化将不会在模块上执行 Initialize() 方法。
当您单击菜单时,这可能会很有用,这将按需加载模块(还不会加载视图),然后您可以通过 EventAggregator 触发事件,因此模块现在可以添加视图(使用命名的方法(不添加视图两次)和激活视图(这将确保视图在该区域中显示)。
希望这可以帮助,
朱利安
You could have your main region be a ContentControl, this way only 1 view will be active at a time.
You can also load your modules "On Demand". There is a Quickstart that shows you how to do this. You should also keep in mind that if the module was already initialized once, initializing it for a second time will not execute the Initialize() method on the module.
It might be useful that when you click on the menu, this will load the module on demand (which will not load the view yet) and then you can fire an event through EventAggregator, so the module can now add the view (use the named approach for not adding the view twrice) and the Activate the view (which will make sure the view is shwon in the region).
Hope this helps,
Julian
为了节省您的时间,请查看 John Papa 的演示框架文章。 如果您有第三个对象(
Screen Conductor
)来处理屏幕在区域中的显示或隐藏,则会更容易。to save you time, check John Papa's Presentation Framework article. It will be more easy if you have 3rd object(
Screen Conductor
) to handle your screens in showing or hiding from regions.