๐Ÿงฑ MVVM in WPF

Windows Presentation Foundation (WPF) fully supports the Model-View-ViewModel (MVVM) pattern, which promotes a clear separation of concerns between the UI and business logic.

The MVVM infrastructure used with Atc.Wpf comes from Atc.XamlToolkit, providing a robust foundation for implementing MVVM effectively, reducing boilerplate code and simplifying development.

โš™๏ธ Features

The MVVM infrastructure is provided by the Atc.XamlToolkit and Atc.XamlToolkit.Wpf packages, which you add to your project directly (Atc.Wpf does not depend on them):

๐Ÿงฉ Component ๐Ÿ“ฆ Source Namespace ๐Ÿ“‹ Description
ViewModelBase Atc.XamlToolkit.Mvvm A base class for ViewModels.
MainWindowViewModelBase Atc.XamlToolkit.Mvvm A base class for the main window ViewModel.
ViewModelDialogBase Atc.XamlToolkit.Mvvm A base class for dialog ViewModels.
ObservableObject Atc.XamlToolkit.Mvvm A base class for observable objects implementing INotifyPropertyChanged.
RelayCommand Atc.XamlToolkit.Command A command supporting CanExecute.
RelayCommand<T> Atc.XamlToolkit.Command A command with a generic parameter and CanExecute.
RelayCommandAsync Atc.XamlToolkit.Command An asynchronous command supporting CanExecute.
RelayCommandAsync<T> Atc.XamlToolkit.Command An asynchronous command with a generic parameter and CanExecute.

๐Ÿ“– For detailed information about source generators and commands, refer to the ViewModel Source Generation documentation.

๐Ÿ” Migrating an existing project from hand-rolled INotifyPropertyChanged / RelayCommand boilerplate? See the Migration guide.

๐Ÿ“ฆ For more information about the MVVM infrastructure, see the Atc.XamlToolkit repository.


๐Ÿš€ Getting started using ViewModelBase

Below is a simple example demonstrating how to create a ViewModel using ViewModelBase:

public class MyViewModel : ViewModelBase
{
    private string myProperty;

    public string MyProperty
    {
        get => myProperty;
        set
        {
            if (myProperty == value)
            {
                return;
            }

            myProperty = value;
            RaisePropertyChanged();
        }
    }
}