Skip to content

CSharpBible MVVM Tutorial

Joe Care edited this page Jan 29, 2025 · 9 revisions

MVVM - Tutorial

Lessons and best practices with the MVVM

Basic concepts

Property-change-notification

The way MVVM works for displaying (generally handling) is by a technique called Property-change-notification. The ViewModel (-class) implements properties for all information that is about to display in a View. It notifies the View (window, Page, UserControl ...) of any change of it's properties. This is done by an event that tells everyone, that a property of an class has changed. The event contains the class as sender, and the name of the possibly changed property.

ICommand-Interface

The ICommand interface is used to signal a UserAction to the ViewModel.
This Interface propagates 3 things:

  • An Execute-Method to execute something.
  • A CanExecute-Function to signal whether the command can be excuted, or not.
  • A CanExecuteChanged-event to signal that the state may have been changed.

The ViewModel exports ICommand-properties, so that the View can bind to them.

Standard concepts

[Dialogs]

[Styles] and [Animation]

Advanced Concepts

[Dependency-Injection]

[Messaging]

[CommunityToolkit.MVVM]

[Multi-Model]

Clone this wiki locally