MVVM与Caliburn:更换所有屏幕?
我是 MVVM 新手,决定在当前项目中使用 Caliburn 和 MEF。该项目基本上是一个基于所选产品的托管屏幕和工作流程的框架。当用户选择产品时,我需要将所有当前屏幕替换为与所选产品相关的屏幕。显然,这必须以模块化方式完成,以便可以根据需要插入或移除产品及其相关屏幕。
我不认为这超出了 Caliburn 的范围,但我不知道如何处理它。谁能提供一些关于如何实现这一目标的见解?
提前致谢。
I am new to MVVM, and decided to use Caliburn and MEF on my current project. The project is basically a framework for hosting screens and workflow based on a selected product. When the user selects a product, I need to swap out all current screens for those relevant to the selected product. Obviously, this has to be done in a modular way, so that products and their associated screens can be plugged in or removed as needed.
I don't think this is beyond the scope of Caliburn, but I'm not sure how to approach it. Can anyone offer some insight into how this might be accomplished?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以做到这一点,具体取决于每种产品类型是否具有独特的导航,或者每种产品之间是否存在共性。
例如,您可以有一个实现
IProduct
接口(用InheritedExport
属性标记)的Product
类型。这些产品类型中的每一个都可以从Conductor
类型派生,并且可以包含它们需要显示的屏幕(项目)列表。ShellViewModel
(可以是Conductor.Collection.OneActive
类型)可以维护由 MEF 导入的IProduct
的集合。导入完成后,此集合可用于填充ShellViewModel
的Items
集合,该集合绑定到产品列表框以供用户选择。当用户从 ListBox 中进行选择时,
ShellViewModel
可以对所选产品调用ActivateItem
。事实上,如果您将 ListBox 命名为
Items
,那么当您在列表中选择一个项目时,ActiveItem
将自动由 Caliburn.Micro 设置,因此活动项目将被自动设置。项目将被设置到适当的产品屏幕。您的 ShellView.xaml 将包含一个名为
ActiveItem
的ContentControl
来显示当前选定的产品(导体)视图。There are a few ways you could do this, depending on whether each product type has a unique navigation, or if there is commonality amongst each product.
For example, you could have a
Product
type which implements anIProduct
interface (marked with theInheritedExport
attribute). Each of these Product types could also derive from theConductor
type and could contain a list of screens (items) that they need to display.The
ShellViewModel
(which can be aConductor<IScreen>.Collection.OneActive
type) could maintain a collection of theIProduct
's imported by MEF. On completion of the import, this collection can be used to populate theShellViewModel
'sItems
collection, which is bound to a ListBox of products for the user to select.When the user makes a selection from the ListBox, the
ShellViewModel
can callActivateItem
on the selected product.In fact, if you give your ListBox the name
Items
, then theActiveItem
will automatically be set by Caliburn.Micro as you select an item in the list, and therefore the active item will be set to the appropriate product screen.Your ShellView.xaml will contain a
ContentControl
with the nameActiveItem
to display the currently selected product (conductor) view.