MVVM & Caliburn : Replacing All Screens?
I am new to MVVM, and decided to use Caliburn and MEF on my current project. The project is basically a framework for hosting开发者_如何学JAVA 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.
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.
精彩评论