ConvMVVM3.SourceGenerator 1.2.0

dotnet add package ConvMVVM3.SourceGenerator --version 1.2.0
                    
NuGet\Install-Package ConvMVVM3.SourceGenerator -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConvMVVM3.SourceGenerator" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConvMVVM3.SourceGenerator" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="ConvMVVM3.SourceGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConvMVVM3.SourceGenerator --version 1.2.0
                    
#r "nuget: ConvMVVM3.SourceGenerator, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConvMVVM3.SourceGenerator@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConvMVVM3.SourceGenerator&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=ConvMVVM3.SourceGenerator&version=1.2.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://github.com/gellston/ConvMVVM3/blob/main/logo.png?raw=true" alt="ConvMVVM3 Logo" width="400"/> </p>

<div align="center">

<a href="https://www.nuget.org/packages/ConvMVVM3.Core"> <img src="https://img.shields.io/nuget/v/ConvMVVM3.Core.svg?style=for-the-badge&logo=nuget&label=NGET%20ConvMVVM3.Core" />

</a>

<a href="https://www.nuget.org/packages/ConvMVVM3.Host"> <img src="https://img.shields.io/nuget/v/ConvMVVM3.Host.svg?style=for-the-badge&logo=nuget&label=NGET%20ConvMVVM3.Host" />

</a>

<a href="https://www.nuget.org/packages/ConvMVVM3.SourceGenerator"> <img src="https://img.shields.io/nuget/v/ConvMVVM3.SourceGenerator.svg?style=for-the-badge&logo=nuget&label=NGET%20ConvMVVM3.SourceGenerator" />

</a>

<br/> <a href="https://www.nuget.org/packages/ConvMVVM3.WPF"> <img src="https://img.shields.io/nuget/v/ConvMVVM3.WPF.svg?style=for-the-badge&logo=nuget&label=NGET%20ConvMVVM3.WPF" />

</a> </div>

ConvMVVM3 (Convergence MVVM3) is an MVVM framework for WPF on Windows, inspired by Prism and Community Toolkit. WPF is currently the only supported UI framework. The Core, Host, and SourceGenerator packages target .NET Standard 2.0, but this does not imply support for other UI frameworks.


πŸ“Œ XAML Namespace Mapping

ConvMVVM3 exposes a single XAML XML namespace for a clean, consistent XAML experience:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3"
    convMVVM3:ViewModelLocator.AutoWireViewModel="True">
</Window>
  • xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3" β†’ ConvMVVM3 XAML features (Regions, ViewModelLocator, Behaviors/Interactivity, etc.)
  • convMVVM3:ViewModelLocator.AutoWireViewModel="True" β†’ ViewModel auto-wiring (Prism-like)

✨ Key Differentiators from Prism & Community Toolkit

πŸš€ UIDispatcher (WPF)

UI thread dispatcher with a WPF implementation:

// Register the WPF dispatcher
services.AddWPFUIDispatcher();      // WPF

// Dispatch to the WPF UI thread
await dispatcher.InvokeAsync(() => Title = "Updated");

πŸ”Œ Smart Dependency Injection (UNIQUE - Built-in)

Lightweight service container with addon system - No external DI required:

// Built-in container - Zero external dependencies
services.AddSingleton<IMyService, MyService>();

πŸ“‘ WeakReference Messenger (Weak References)

Thread-safe messaging with automatic cleanup:

// Messaging using weak references
WeakReferenceMessenger.Default.Send<Message>(this, newData);

🎯 Region System (Prism-inspired, WPF)

Built-in region management for WPF controls:


<ContentControl convMVVM3:RegionPlugin.RegionName="MainContent" />

⚑ Source Generator (Community Toolkit-inspired)

Automatic property and command generation with enhanced features:

[ObservableProperty] private string title;       // Generates Title property
[RelayCommand] private void Save();              // Generates SaveCommand
[AsyncRelayCommand] private async Task Load();   // Generates LoadCommand

πŸ—οΈ Architecture Overview

Core MVVM Components (Platform-Agnostic)

ConvMVVM3.Core/
β”œβ”€β”€ ObservableObject              # Base class with INotifyPropertyChanged
β”œβ”€β”€ ObservableRecipient           # Message recipient base class
β”œβ”€β”€ UIDispatcher                  # UI dispatcher abstraction
β”œβ”€β”€ WeakReferenceMessenger        # Memory-safe messaging system
β”œβ”€β”€ Commands/
β”‚   β”œβ”€β”€ RelayCommand              # Synchronous command implementation
β”‚   └── AsyncRelayCommand         # Async command with cancellation
└── DependencyInjection/          # DI abstractions (implementation in Host)

WPF Implementation (Windows)

ConvMVVM3.WPF/                    # WPF-specific implementation
β”œβ”€β”€ Regions/                      # Region system (Prism-inspired)
β”œβ”€β”€ WPFUIDispatcher               # WPF-specific dispatcher
β”œβ”€β”€ Behaviors/                    # Behaviors / triggers / actions
└── Locator/                      # ViewModel auto-wiring

Source Generation

ConvMVVM3.SourceGenerator/
β”œβ”€β”€ ObservableProperty generation # Auto property implementation
β”œβ”€β”€ RelayCommand generation       # Auto command creation
β”œβ”€β”€ Dependency tracking           # Smart property notification
└── Compile-time validation       # Early error detection

πŸ“ Project Structure

ConvMVVM3.Core/                   # Platform-agnostic MVVM library
ConvMVVM3.SourceGenerator/        # Property and command source generator
ConvMVVM3.WPF/                    # WPF-specific interactivity + regions
ConvMVVM3.Host/                   # DI host implementation
ConvMVVM3.WPF.Tests/              # WPF unit tests
ConvMVVM3.Tests/                  # Core unit tests

πŸ› οΈ Installation

dotnet add package ConvMVVM3.WPF

πŸš€ Quick Start

1) Basic WPF ViewModel with Source Generation

// ViewModel for a WPF application
public partial class MainViewModel : ObservableObject
{
    [ObservableProperty]
    private string title = "Hello ConvMVVM3!";

    [RelayCommand]
    private void ShowMessage() => MessageBox.Show(Title);

    [AsyncRelayCommand]
    private async Task LoadDataAsync()
    {
        Title = "Loading...";
        await Task.Delay(1000);
        Title = "Data Loaded!";
    }
}

2) ViewModelLocator (AutoWireViewModel)

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3"
    convMVVM3:ViewModelLocator.AutoWireViewModel="True">
    
</Window>

3) WPF UIDispatcher Integration

// Register in the WPF application service registry
services.AddWPFUIDispatcher();       // WPF

// Inject IUIDispatcher into the ViewModel
public partial class MyViewModel : ObservableObject
{
    private readonly IUIDispatcher _dispatcher;

    public MyViewModel(IUIDispatcher dispatcher)
    {
        _dispatcher = dispatcher;
    }

    [AsyncRelayCommand]
    private async Task UpdateFromBackgroundAsync()
    {
        var data = await Task.Run(() => GetHeavyData());

        // Update on the WPF UI thread
        await _dispatcher.InvokeAsync(() => Title = data);
    }
}

4) WPF Region Management


<Grid>
    <ContentControl convMVVM3:RegionPlugin.RegionName="MainContent" />
</Grid>
// Navigate within a WPF region
_regionManager.RequestNavigate("MainContent", typeof(HomeView));
ViewModel navigation callbacks (WPF)

Bootstrapper registers AddWPFRegionManager() automatically. If configuring the container without a bootstrapper, call services.AddWPFRegionManager() instead of the Core-only AddRegionManager().

Keep ViewModelLocator.AutoWireViewModel="True" on the View in XAML and implement INavigationAware on its ViewModel. The View only needs InitializeComponent(); constructor injection of the ViewModel and manual callback forwarding are unnecessary. The WPF adapter completes opted-in wiring before navigation callbacks, without waiting for Loaded. It preserves existing DataContexts, explicit nulls, and bindings. An opted-in View whose DataContext cannot be connected causes navigation to fail before the current content is replaced.

public class CustomerViewModel : ObservableObject, INavigationAware
{
    public bool IsNavigationTarget(NavigationContext context) => true;

    public void OnNavigatedTo(NavigationContext context)
    {
        if (context.Parameters.TryGetValue("CustomerId", out var customerId))
        {
            // Initialize the screen for this customer.
        }
    }

    public void OnNavigatedFrom(NavigationContext context)
    {
        // Store screen state or cancel outstanding work.
    }
}

regionManager.RequestNavigate<CustomerView>("MainContent",
    new NavigationParameters { ["CustomerId"] = 123 });

The single-view RequestNavigate overloads (type, generic, and service key) notify both the View and its DataContext, in that order, using the same navigation context. The same instance is never notified twice by the adapter. Remove any existing View-to-ViewModel forwarding code when enabling automatic dispatch to both. Each participant's IsNavigationTarget still gates only its own OnNavigatedTo; it does not cancel navigation or implement Prism-style view reuse. Multi-view item addition, Active, and ClearRegion retain their existing notification behavior.

ViewModelLocator.EnsureViewModelConnected(view) can also be called explicitly on the View's dispatcher thread. It returns whether a non-null DataContext exists; repeated calls preserve an already connected transient ViewModel. Explicit local nulls and bindings are never overwritten; opt out of automatic wiring if they are intended to remain null during navigation.

The WPF project references local Core to compile the new resolver contract. Before publishing this change, increase the Core and WPF package versions so the generated WPF package dependency requires the Core release containing this contract.

5) Weak Reference Messaging

// Sender
WeakReferenceMessenger.Default.Send<DataUpdatedMessage>(this, newData);

// Receiver
public partial class MyViewModel : ObservableObject, IRecipient<DataUpdatedMessage>
{
    public void Receive(DataUpdatedMessage message)
    {
        Title = message.Data;
    }
}

6) WPF Interactivity / Behaviors

<Button Content="Click Me">
    <convMVVM3:Interaction.Triggers>
        <convMVVM3:EventTrigger EventName="Click">
            <convMVVM3:InvokeCommandAction Command="{Binding SaveCommand}" />
        </convMVVM3:EventTrigger>
    </convMVVM3:Interaction.Triggers>
</Button>

🧰 Helpful Utilities

This section includes a few practical helpers used frequently in Prism-style MVVM apps:

  • ConvMVVM3.Core.Mvvm.Threading
  • ConvMVVM3.Core.Mvvm.Collections
  • ConvMVVM3.Host.DependencyInjection

A) BusyScope β€” ConvMVVM3.Core.Mvvm.Threading

Use a scope to ensure IsBusy is always restored (even if an exception occurs).
Recommended for simple β€œsingle operation” flows.

using ConvMVVM3.Core.Mvvm.Threading;

// In your ViewModel
private bool _isBusy;
public bool IsBusy
{
    get => _isBusy;
    set { _isBusy = value; /* RaisePropertyChanged */ }
}

public async Task RefreshAsync()
{
    using (BusyScope.Enter(v => IsBusy = v))
    {
        await LoadAsync();
    }
}

Recommended when operations can overlap (nested calls, multiple async commands).

using ConvMVVM3.Core.Mvvm.Threading;

private int _busyCount;
private bool _isBusy;
public bool IsBusy
{
    get => _isBusy;
    set { _isBusy = value; /* RaisePropertyChanged */ }
}

public async Task RefreshAsync()
{
    using (BusyCounterScope.Enter(
        getCount: () => _busyCount,
        setCount: v => _busyCount = v,
        setBusy:  v => IsBusy = v))
    {
        await LoadAsync();
    }
}

C) OperationGuard β€” ConvMVVM3.Core.Mvvm.Threading

Prevents re-entrancy (double-click save, multiple async executions).
Combine it with BusyScope/BusyCounterScope for a great UX.

using ConvMVVM3.Core.Mvvm.Threading;

private readonly OperationGuard _saveGuard = new OperationGuard();
private int _busyCount;

public Task SaveAsync()
{
    return _saveGuard.RunAsync(async () =>
    {
        using (BusyCounterScope.Enter(
            () => _busyCount,
            v => _busyCount = v,
            v => IsBusy = v))
        {
            await SaveAsyncCore();
        }
    });
}

D) ObservableRangeCollection β€” ConvMVVM3.Core.Mvvm.Collections

Use AddRange/ReplaceRange to avoid thousands of per-item collection change notifications.

using ConvMVVM3.Core.Mvvm.Collections;

public ObservableRangeCollection<ItemViewModel> Items { get; } = new();

public async Task LoadItemsAsync()
{
    var items = await LoadFromServerAsync();

    // One reset notification instead of N adds
    Items.ReplaceRange(items);
}

E) ActivatorUtilities β€” ConvMVVM3.Host.DependencyInjection

ActivatorUtilities helps create objects by mixing:

  • DI-resolved services from IServiceResolver
  • runtime arguments you provide (e.g., IDs, parameters, view references)
using ConvMVVM3.Core.DependencyInjection.Abstractions;
using ConvMVVM3.Host.DependencyInjection;

// Example types
public sealed class UserDetailsViewModel
{
    public UserDetailsViewModel(IUserService service, int userId)
    {
        // service comes from DI, userId comes from runtime args
    }
}

public static class Example
{
    public static void CreateWithRuntimeArgs(IServiceResolver resolver)
    {
        // 1) CreateInstance: DI + runtime args
        var vm = (UserDetailsViewModel)ActivatorUtilities.CreateInstance(
            resolver,
            typeof(UserDetailsViewModel),
            123);

        // 2) GetServiceOrCreateInstance: prefer registered instance, otherwise create
        var shell = ActivatorUtilities.GetServiceOrCreateInstance<MainShellViewModel>(resolver);

        // 3) CreateFactory: preselect ctor + argument mapping for speed
        var factory = ActivatorUtilities.CreateFactory(
            typeof(UserDetailsViewModel),
            new[] { typeof(int) });

        var vmFast = (UserDetailsViewModel)factory(resolver, new object[] { 456 });
    }
}

🧩 Bootstrapper

ConvMVVM3 supports a Prism-style Bootstrapper flow for registering modules, building the shell, and initializing regions/services.

public class AppBootStrapper : Bootstrapper
{
    protected override void ConfigureRegion(IRegionManager regionManager)
    {
    }

    protected override Window CreateShell(IServiceContainer provider)
    {
        return (Window)provider.GetService("MainWindowView");
    }

    protected override void OnInitialized(IServiceContainer provider)
    {
    }

    protected override void RegisterModules()
    {
        this.RegisterModule<AModule>();
        this.RegisterModule<BModule>();
        this.RegisterModule<CModule>();
        this.RegisterModule<MainModule>();
    }

    protected override void RegisterServices(IServiceRegistry container)
    {
    }
}

🎯 Supported Platform

WPF on Windows is currently the only supported UI framework.

Component Target frameworks
Core, Host, SourceGenerator .NET Standard 2.0
WPF integration .NET Framework 4.8; .NET 6, 7, 8, 9, 10 for Windows
Example WPF applications .NET 10 for Windows

The framework includes WPF implementations for regions, UI dispatching, ViewModel location, and behaviors.


πŸ“„ License

MIT License - see LICENSE file


ConvMVVM3: An MVVM framework for WPF combining modular application composition with property and command source generation.

Support for additional UI frameworks is not currently provided.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ConvMVVM3.SourceGenerator:

Package Downloads
ConvMVVM3.WPF

ConvMVVM3 Core MVVM library (platform-agnostic).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 104 11/6/2026
1.1.0 174 4/8/2026
1.0.3 157 2/9/2026
1.0.2 136 2/8/2026
1.0.1 141 2/8/2026