liveBook · Manning

BaseViewModel

As explained in .NET MAUI in Action

A base viewmodel is a reusable superclass that provides shared state, behavior, and notification functionality to page-specific viewmodels.

A BaseViewModel is a reusable superclass for page-specific ViewModels. It centralizes UI notification and shared page state, so each derived ViewModel avoids repeating the same implementation. section 9.5.2

A practical BaseViewModel commonly provides:

  • INotifyPropertyChanged and OnPropertyChanged so bound views respond when ViewModel state changes. section 9.5.2
  • Title and IsLoading properties for state shared across pages. section 9.5.2
  • An INavigation property when the application uses navigation paradigms that require access to the navigation stack. section 9.5.2

Deriving a page ViewModel

InputViewModel inherits from BaseViewModel, then adds page-specific commands, search results, a selected product, and a count. The shared notification and page-state behavior remains in the base class.

How .NET MAUI in Action covers it

How deep it goes
Implements property-change notification and shared properties, then stops short of detailing the complete class implementation.
Examples
Uses BaseViewModel.cs, shared Title and IsLoading properties, and an InputViewModel with commands and product data.
What it assumes
Assumes page-specific ViewModels and UI binding requirements, while teaching shared behavior through inheritance.
What you can do after
Build reusable ViewModels by placing shared notification and page state in a base class and deriving specialized ViewModels from it.
How it connects
Connects MVVM, INotifyPropertyChanged, data binding, ViewModels, and application navigation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.