Navigation - STARIONGROUP/COMET-IME-Community-Edition GitHub Wiki
The CDP4-COMET MVVM framework is based on the view-model first approach. View-Models are instianted in the application and later bound to a corresponding View. The different NavigationServices are responsible for constructing a View and properly setting the DataContext.
The CDP4-COMET MVVM framework provides 3 NavigationServices to navigate or open specific kinds of viewmodel/view combinations.
- PanelNavigationService
- ThingDialogNavigationService
- DialogNavigationService
Each of these services implements a corresponding Interface and is injected using MEF.
The PanelNavigationService
is used to navigate to so-called panels or browsers, these browsers are placed in a region in the shell. Typically these views contain a treelist, listview or canvas. The Open
and Close
methods are used to navigate to a Panel, or to close the Panel. In order for a Panel or Browser to be opened and closed by the PanelNavigationService
the view-model needs to implement the IPanelViewModel
interface; the corresponding view needs to implement (in the code behind - .xaml.cs) the IPanelView
interface and it needs to be decorated with the PanelViewExport
attribute to state in what region the view needs to be placed. The most frequent methods of the PanelNavigationService
are:
/// <summary>
/// Opens the view associated to the provided view-model
/// </summary>
/// <param name="viewModel">
/// The <see cref="IPanelViewModel"/> for which the associated view needs to be opened
/// </param>
/// <param name="useRegionManager">
/// A value indicating whether handling the opening of the view shall be message-based or not. In case it is
/// NOT message-based, the <see cref="IRegionManager"/> handles opening and placement of the view.
/// </param>
/// <remarks>
/// The data context of the view is the <see cref="IPanelViewModel"/>
/// </remarks>
void Open(IPanelViewModel viewModel, bool useRegionManager);
/// <summary>
/// Closes the <see cref="IPanelView"/> associated to the <see cref="IPanelViewModel"/>
/// </summary>
/// <param name="viewModel">
/// The view-model that is to be closed.
/// </param>
/// <param name="useRegionManager">
/// A value indicating whether handling the opening of the view shall be handled by the region manager. In case this region manager does not handle
/// this it will be event-based using the <see cref="CDPMessageBus"/>.
/// </param>
void Close(IPanelViewModel viewModel, bool useRegionManager);
Another method is also available: OpenExistingOrOpen
.
Sometimes a view and view-model stay in memory even when it isn't visible.
When that happens, the logic of closing a panel will be the responsibility of another class, not the PanelNavigationService
.
When this method is used and the view-model is already in the PanelNavigationService
's cache (ViewModelViewPairs
property), then a NavigationPanelEvent
will be sent to the CDPMessageBus
. The other class will then be able to handle re-opening of the view.
If the view-model is not found in the PanelNavigationService
's cache (ViewModelViewPairs
property), then a normal Open
action will be performed.
The PanelNavigationService
is populated at startup by MEF. All the CDP4-COMET plugings are inspected for classes that implement IPanelViewModel
and IPanelView
.
More information coming soon
More information coming soon
More information coming soon