VRT.Mvvm.Navigation 1.0.1

dotnet add package VRT.Mvvm.Navigation --version 1.0.1
                    
NuGet\Install-Package VRT.Mvvm.Navigation -Version 1.0.1
                    
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="VRT.Mvvm.Navigation" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VRT.Mvvm.Navigation" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="VRT.Mvvm.Navigation" />
                    
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 VRT.Mvvm.Navigation --version 1.0.1
                    
#r "nuget: VRT.Mvvm.Navigation, 1.0.1"
                    
#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 VRT.Mvvm.Navigation@1.0.1
                    
#: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=VRT.Mvvm.Navigation&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=VRT.Mvvm.Navigation&version=1.0.1
                    
Install as a Cake Tool

VRT.Mvvm

Shared, toolkit-agnostic MVVM navigation core for .NET applications (WinForms, WPF, MAUI, and similar hosts).

Packages

Package Contents When to reference
VRT.Mvvm.Navigation Runtime + embedded source generators Default — apps and libraries that define Views
VRT.Mvvm.Navigation.Generators Generators only (DevelopmentDependency) Optional — multi-project layouts or explicit analyzer reference
<PackageReference Include="VRT.Mvvm.Navigation" Version="*" />

Features

  • Navigate by ViewModel type via a single INavigationService entrypoint
  • Session View+ViewModel cache with suspend/dispose (INavigationWorkspace)
  • Explicit View ↔ ViewModel registration (IComponentLocator / DI helpers)
  • Hosts display views via toolkit-specific IRoutingHandler.ShowView(object view)
  • Lightweight NavigationResult / NavigationResult<T> with internal Bind / Tap / Map
  • Roslyn generators: AddMvvmComponents and partial ViewModel properties for IViewFor<T>

Requirements

  • .NET 10 (library targets net10.0)
  • Microsoft.Extensions.DependencyInjection.Abstractions (transitive)
  • Host app typically uses Microsoft.Extensions.DependencyInjection

Quick start

using Microsoft.Extensions.DependencyInjection;
using VRT.Mvvm.Navigation;
using VRT.Mvvm.Navigation.Abstractions;

var services = new ServiceCollection();
services.AddNavigation();
// Manual mappings, or generated for all IViewFor<> in this assembly:
// services.AddNavigationComponent<HomeView, HomeViewModel>();
services.AddMvvmComponents(); // from source generator (ships with the NuGet package)

await using var provider = services.BuildServiceProvider();

var navigation = provider.GetRequiredService<INavigationService>();
// Host implements IRoutingHandler and registers itself:
// navigation.RegisterRoutingHandler(this);

await navigation.NavigateToAsync<HomeViewModel>(
    configure: vm => { /* optional setup */ },
    cacheView: true);

Terminology

Name Meaning
ViewModel type What you navigate to (NavigateToAsync<TViewModel>)
View UI instance delivered to the host (ShowView(view))
MvvmComponent (internal) Type declaration: View type ↔ ViewModel type (locator)
MvvmComponentInstance (internal) Live View + ViewModel instances (session cache)

Host responsibilities

  1. Implement IRoutingHandler.ShowView(object view) to place the view in the UI (content control, panel, frame, …).
  2. Call INavigationService.RegisterRoutingHandler(this) on startup (do not register the host in DI if that creates a cycle with INavigationService).
  3. Register navigable pairs via AddMvvmComponents() (generated) and/or AddNavigationComponent<TView, TViewModel>().

Views and ViewModels

Views should be partial and implement IViewFor<TViewModel>:

  • One IViewFor<T> → generator emits public TViewModel? ViewModel { get; set; }
  • Several IViewFor<> on the same view → generator emits explicit TViewModel? IViewFor<TViewModel>.ViewModel properties (avoids name/type clash)
  • Hand-written ViewModel members are left as-is

Optional ISuspendable pauses inactive screens; IDisposable is honored when the workspace discards or evicts a pair.

Navigation injects the active ViewModel via public DataContext / ViewModel when assignable, and via matching IViewFor<T> (including explicit implementations).

Cache behavior

Session cache is keyed by ViewModel type (one View class may back multiple ViewModels).

cacheView Behavior
true (default) Reuse the same View+ViewModel pair for that ViewModel type; previous cached pairs are suspended, not disposed
false Create a fresh pair; when leaving, dispose the previous transient pair if it was not cached

Call INavigationWorkspace.Clear() on logout (or similar) to dispose all cached screens.

Multi-project with Views

Each project that defines IViewFor<> views and should get generated AddMvvmComponents / ViewModel properties must compile with the generator (via VRT.Mvvm.Navigation or VRT.Mvvm.Navigation.Generators). Call AddMvvmComponents() per assembly that contains views.

Design notes

  • Core has no WPF / WinForms / MAUI types.
  • No MediatR / CSharpFunctionalExtensions dependency.
  • Source generators ship with the main package; optional standalone Generators package for advanced layouts.

License

MIT — see LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 113 8/9/2026