Skip to main content

MVVM Patterns

Overview

The Model-View-ViewModel pattern implementation in MiniMrpOrderCreation provides clean separation between UI and business logic, enabling testability and maintainability.

ViewModel Base Classes

BaseViewModel

Core functionality for all ViewModels:

  • INotifyPropertyChanged implementation
  • Command binding support
  • Disposal pattern
  • Property change notification helpers

BaseRouteableViewModel

Navigation-aware ViewModels:

  • Navigation lifecycle hooks
  • Parameter passing
  • State preservation
  • Memory cleanup on navigation

Data Binding Patterns

Property Binding

private string _searchString;
public string SearchString
{
get => _searchString;
set
{
if (_searchString != value)
{
_searchString = value;
OnPropertyChanged();
}
}
}

Command Binding

public RelayCommand SearchCmd { get; private set; }
SearchCmd = new RelayCommand(ExecuteSearch, CanExecuteSearch);

Collection Binding

public ObservableCollection<Item> Items { get; }
public BindingList<SelectedItem> SelectedItems { get; }

Communication Patterns

Event Aggregation

Cross-ViewModel communication without coupling.

Messenger Pattern

Lightweight message passing between components.

Service Mediation

Services coordinate ViewModel interactions.

Best Practices

  • One ViewModel per View
  • No UI references in ViewModels
  • Use commands for all actions
  • Implement proper disposal
  • Test ViewModels independently