Skip to content

Region Based Navigation

kobi2294 edited this page May 12, 2019 · 2 revisions

Region Based Navigation

MvvmKit has a navigation concept that is based or regions. A Region is a logical representation of an area in the UI where you can place a view, backed by a view model. Before we go on and explain the navigation concept, we need to define a few terms.

Component

In MvvmKit - when we say Component, we mean a combination of view and view model.

The main equation of MVVM says that View.DataContext==ViewModel. In MvvmKit, A view and view model that are bound together are called Component

Region

The UI is made of a hierarchical structure of components. Each component may contain additional component. For example, the main screen may hold a toolbar, a list of items, and a preview for the selected item. The toolbar may be divided into parts, and so on. Each such part is called a "Region". A region has representation both in the visual world (views) and in the logical world (view models). In the visual world it represents an area that may contain a view. In the logical world it has a specific role in the application.

For example, assume that you have an email application where you can view your mails list on the left, and when you click on an email, you see it's preview in the center. The "left" area may be called the "List Region" where you will place the "Mails List Component". The center area may be called the "Preview Region" where you will place Preview components. You may even change components in this region based on the currently selected email.

Navigation is the action of setting a specific component to a region.

Region Host

Since each region may hold a component, we need a visual control to contain the component view. This is called the "Region Host". A Region Host will always be an instance of a class that derives from ContentControl. It will have the view model as it's content, and the DataTemplate will present it's view.

Region Manager

Each region has an attached object that manages navigation to the region. The region manager is responsible for the following:

  • Storing, subscribing and unsubscribing Region Hosts.
  • Instantiation of the view model.
  • Calling the life cycle methods (Initialize, Activate and Deactivate) when needed.
  • Setting the view model as content of all Region Hosts.

Regions Service

The regions service is responsible for all the regions and region managers in the application. You may register and unregister regions into it. When you register a region, it creates and assigns a region manager to the region.

Region Behavior

A region behavior is an attachment you may add to a region. It listens to region navigation events and may respond to them. For example, a region behavior may create a region host when the region is navigated into.

Region Host Behavior

A region host behavior is an attachment to a region host. It listens to the region host navigation and lifecycle events and may respond to them. For example, assume that a popup is a region host, it may change it's IsOpen property based on region navigation events.

Clone this wiki locally