liveBook · Manning

Viewmodel-first approach

As explained in .NET MAUI in Action

A viewmodel-first approach is an application-building technique that establishes functional viewmodel behavior before constructing the corresponding view.

Build the functional ViewModel before constructing its corresponding view. This approach suits developers who think in functional design, reduces visual-design cognitive load, and lets UI and functionality develop independently. section 9.5.2

Choose the starting point according to the task and team:

  • Start with the ViewModel when functional requirements, testable behavior, or service interactions are clearer than the visual design. section 10.3.1
  • Start with the view when visual design leads the work, a framework favors that direction, or a UI designer has already supplied the interface. section 9.5.2
  • Develop both sides in parallel with MVVM, then connect them through binding and dependency injection. section 9.5.2 section 10.3.1

Build a report page from the ViewModel outward

Create ReportViewModel with an observable inventory collection and an injected inventory service. Add Init to avoid repeated initialization and Refresh to load data, clear and repopulate the collection, and update IsLoading. Register the ViewModel, inject it into ReportPage, assign BindingContext, and call Init from OnAppearing. Add the XAML only afterward, binding the loading indicator and CollectionView to the ViewModel. section 10.3.1

How .NET MAUI in Action covers it

How deep it goes
Demonstrates a procedural ViewModel-to-page workflow with initialization, refresh, registration, injection, lifecycle wiring, and bindings.
Examples
Uses InputViewModel and ReportViewModel examples with commands, collections, service calls, loading state, and page bindings.
What it assumes
Assumes familiarity with C#, MVVM, ViewModels, pages, dependency injection, and data binding.
What you can do after
Build functional ViewModels, register and inject them, connect page lifecycle events, and add matching UI afterward.
How it connects
Connects MVVM with View-first development, data binding, dependency injection, lifecycle methods, and testing.

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.