MVVM与Caliburn:更换所有屏幕?

发布于 2024-10-30 05:11:43 字数 219 浏览 4 评论 0原文

我是 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 技术交流群。

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

发布评论

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

评论(1

苄①跕圉湢 2024-11-06 05:11:43

有几种方法可以做到这一点,具体取决于每种产品类型是否具有独特的导航,或者每种产品之间是否存在共性。

例如,您可以有一个实现 IProduct 接口(用 InheritedExport 属性标记)的 Product 类型。这些产品类型中的每一个都可以从 Conductor 类型派生,并且可以包含它们需要显示的屏幕(项目)列表。

ShellViewModel(可以是 Conductor.Collection.OneActive 类型)可以维护由 MEF 导入的 IProduct 的集合。导入完成后,此集合可用于填充 ShellViewModelItems 集合,该集合绑定到产品列表框以供用户选择。

当用户从 ListBox 中进行选择时,ShellViewModel 可以对所选产品调用 ActivateItem

事实上,如果您将 ListBox 命名为 Items,那么当您在列表中选择一个项目时,ActiveItem 将自动由 Caliburn.Micro 设置,因此活动项目将被自动设置。项目将被设置到适当的产品屏幕。

您的 ShellView.xaml 将包含一个名为 ActiveItemContentControl 来显示当前选定的产品(导体)视图。

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 an IProduct interface (marked with the InheritedExport attribute). Each of these Product types could also derive from the Conductor type and could contain a list of screens (items) that they need to display.

The ShellViewModel (which can be a Conductor<IScreen>.Collection.OneActive type) could maintain a collection of the IProduct's imported by MEF. On completion of the import, this collection can be used to populate the ShellViewModel's Items 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 call ActivateItem on the selected product.

In fact, if you give your ListBox the name Items, then the ActiveItem 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 name ActiveItem to display the currently selected product (conductor) view.

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