Skip to content

About

Simplifies dialogs access from view models when using MVVM in .NET

Resources

Stars

228 stars

Watchers

4 watching

Forks

Repository files navigation

MVVM Dialogs
MVVM Dialogs

Simplifies dialogs access from view models when using MVVM in .NET

Why MvvmDialogs?

It allows to leave your View code-behind entirely empty, without Interaction requests. You get a clean separation between the View and the ViewModels. You know the design is clean when all Views are empty of code.

It allows writing unit tests for view models in the same manner unit tests are written for other classes.

This matters especially in the era of AI building spaghetti code on auto-pilot. This allows you to entirely separate visual concerns from logic concerns. It forces AI to maintain a clean boundary that prevents spaghetti code creep.

It also gives you the possibility to switch the UI at any point with little efforts.

If you want to know what MVVM is and why it matters, check out my tutorial Build Modern Cross-Platform Apps with .NET. https

UI Frameworks currently supported:

Framework Targets NuGet
Avalonia Desktop, Mobile, Browser Avalonia package
WPF Desktop WPF package
WinUI 3 Windows WinUI 3 package
MAUI Desktop, Mobile MAUI package
Uno Desktop, Mobile, Browser Uno package

Shared library package Source generator package

Handles

  • Modal and child windows
  • Recursive closure confirmation and veto
  • File dialogs and access
  • Message boxes and popups
  • Single-page navigation mode and back button for mobile
  • ViewModel as document tabs, or as dock panels, with custom implementation

This documentation is for v3; v2.4 is here..

Generic Usage

The interface IDialogService provides a platform-agnostic way of managing dialogs:

using HanumanInstitute.MvvmDialogs

public class BaseViewModel : INotifyPropertyChanged
{
    private readonly IDialogService dialogService;

    public BaseViewModel(IDialogService dialogService)
    {
        this.dialogService = dialogService;
    }

    // ...

    private async Task ShowDialogAsync()
    {
        var vm = dialogService.CreateViewModel<AddTextViewModel>();

        bool? success = await dialogService.ShowDialogAsync(this, vm);
        if (success == true)
        {
            Results.Add(vm.Text);
        }
    }
}

Meanwhile...

  • You can use IDialogService within class libraries that have no reference to Avalonia nor Wpf (referencing only HanumanInstitute.MvvmDialogs)
  • It is friendly for unit tests

Documentation

Demos

Demos are available for all platforms.

Beginner: Quickstart showing basic usage.

Intermediate: Gallery showing all common features.

Advanced: Workspace showing views in tabs and dock panels.

Pro: PhotoCraft controlling an external app from ViewModel via custom IView.

Credits

The original design came from FantasticFiasco/mvvm-dialogs. Migration guide

License

MIT License

Author

Etienne Charland — Coherence Programming | Reality Engineering | Soul Architect

Dealing with structural failures?

Consulting services available — including a free architectural coherence scan.

About

Simplifies dialogs access from view models when using MVVM in .NET

Resources

Stars

228 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages