Skip to content

Mvvm Framework

kobi2294 edited this page May 19, 2019 · 9 revisions

The Mvvm Framework

The Mvvm Kit is a strongly opinionated framework the helps to build advanced WPF applications.

Getting Started

To create an MvvmKit application, do the following:

  1. Create a new project using the Mvvm Kit Project Template for visual studio
  2. Create Components using the Mvvm Kit Component Template for visual studio
  3. The view model is inherited from ComponentBase, add bindable properties and delegate commands to it.
  4. Each Component comes with a resource dictionary for design time data, add design time instances of your view model
  5. Draw the view using the Design Time Data.
  6. Creates Model services by inheriting from ServiceBase
  7. Add the services to the Unity container in the Bootstrapper.
  8. Consume the services in the view models by declaring them in the Inject Method.
  9. Expose service state changes using AsyncEvent
  10. Define global regions in the application using the GlobalRegions static class
  11. Define region hosts in the container view by using the GlobalHost attached properties
  12. If the region has a small constant set of possible views, you can define a router for that region and use it for navigation. Otherwise, you can perform navigations directly on the region using the region manager.
  13. You can define Dialog Components by inheriting the view model from DialogBase instead of ComponentBase.
  14. You can run the dialogs and collect the results using the regions manager and a dedicated dialogs host.

Core Concepts

Core classes

View Resolution

  • The IViewResolver interface contains a single method that accepts a view model type and returns the matching view type. You may implement it in order to define a rule that matches view and view model types.
  • The DefaultViewResolver class is a default such implementation that removes the Vm postfix and replaces it with View, which answers to the naming standart of the MvvmKit.
  • The DataTemplateWrapper class is an internal static class that contains a method that accepts view model type and view type, and builds a data template for the view model type, that creates an instance of the view type.
  • The ViewTemplateSelector class is a DataTemplateSelector that creates a view for a view model content. It uses an injected IViewResolver to find the matching view type, and then constructs the DataTemplate using DataTemplateWrapper