RoccoZero.AsyncNavigation 2.0.3

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

AsyncNavigation

This fork is packaged as RoccoZero.AsyncNavigation.Avalonia, with the matching RoccoZero.AsyncNavigation core dependency. Assembly names, namespaces and XAML namespace mappings remain compatible with upstream.

The Avalonia adapter uses compiled/property bindings for NativeAOT. During DI shutdown, the view manager releases cache references and lets the service provider dispose its views and view models. Explicit Clear() and Remove(dispose: true) retain their cleanup behavior. Custom factories own the objects they create.

A lightweight async navigation framework for .NET desktop apps, built on Microsoft.Extensions.DependencyInjection.

CI NuGet NuGet NuGet WinUI 3 License: MIT .NET

中文文档 · Live Demo


Features

Async/Await Native Navigation is fully async end-to-end with CancellationToken support
DI-First Views and view models are resolved from the DI container
Navigation Guard Block navigation away with INavigationGuard (e.g. unsaved changes)
Interceptors Run cross-cutting logic (auth, analytics) via INavigationInterceptor
Dialog Service Async dialog and window management built-in
Multiple Region Types ContentControl, ItemsControl, and TabControl regions
History Navigation GoForwardAsync / GoBackAsync out of the box
Lifecycle Management Automatic view caching, eviction, and disposal — no memory leaks
Native AOT Full Avalonia AOT / trimming support, zero extra config
Framework-Agnostic Works with any MVVM framework
Minimal Deps Only Microsoft.Extensions.DependencyInjection.Abstractions >= 8.0

Platform Support

Platform Status Package / Sample
Avalonia Stable AsyncNavigation.Avalonia
WPF Stable AsyncNavigation.Wpf
WinUI 3 In development Sample.WinUI

WinUI 3 support is under active development. It includes content, items, tab, NavigationView, dialog, window, and indicator support, but its APIs and behavior may still change. Test it carefully before using it in production.


Installation

# Avalonia
dotnet add package AsyncNavigation.Avalonia

# WPF
dotnet add package AsyncNavigation.Wpf

WinUI 3 is currently available from source and through the repository sample while development continues.


Quick Start

1. Register services

services.AddNavigationSupport()
        .RegisterView<HomeView, HomeViewModel>("Home")
        .RegisterView<SettingsView, SettingsViewModel>("Settings")
        .RegisterDialog<ConfirmView, ConfirmViewModel>("Confirm");

2. Declare a region in XAML

xmlns:an="https://github.com/NeverMorewd/AsyncNavigation"

<ContentControl an:RegionManager.RegionName="MainRegion" />

3. Navigate

// Navigate
await _regionManager.RequestNavigateAsync("MainRegion", "Home");

// History
await _regionManager.GoBackAsync("MainRegion");
await _regionManager.GoForwardAsync("MainRegion");

// Dialog
var result = await _dialogService.ShowViewDialogAsync("Confirm");

4. React to navigation in view models

View models implement INavigationAware directly. NavigationAwareBase remains available for compatibility but is obsolete; new code should implement INavigationAware. You can define an application base class to share default implementations.

using AsyncNavigation;
using AsyncNavigation.Abstractions;
using AsyncNavigation.Core;
using System.Threading;
using System.Threading.Tasks;

public class HomeViewModel : INavigationAware
{
    public event AsyncEventHandler<AsyncEventArgs>? AsyncRequestUnloadEvent;

    public Task InitializeAsync(NavigationContext context) => Task.CompletedTask;

    public Task OnNavigatedToAsync(NavigationContext context)
    {
        // Load page data here; use context.CancellationToken for async operations.
        return Task.CompletedTask;
    }

    public Task OnNavigatedFromAsync(NavigationContext context) => Task.CompletedTask;
    public Task OnUnloadAsync(CancellationToken cancellationToken) => Task.CompletedTask;

    // Allow reuse when caching is enabled; return false to request a new instance.
    public Task<bool> IsNavigationTargetAsync(NavigationContext context) => Task.FromResult(true);
}

public class EditViewModel : INavigationAware, INavigationGuard
{
    public bool HasUnsavedChanges { get; set; }
    public event AsyncEventHandler<AsyncEventArgs>? AsyncRequestUnloadEvent;

    public Task InitializeAsync(NavigationContext context) => Task.CompletedTask;
    public Task OnNavigatedToAsync(NavigationContext context) => Task.CompletedTask;
    public Task OnNavigatedFromAsync(NavigationContext context) => Task.CompletedTask;
    public Task OnUnloadAsync(CancellationToken cancellationToken) => Task.CompletedTask;
    public Task<bool> IsNavigationTargetAsync(NavigationContext context) => Task.FromResult(true);

    public Task<bool> CanNavigateAsync(NavigationContext context, CancellationToken ct)
    {
        // Return false to cancel; show a confirmation dialog asynchronously here if needed.
        return Task.FromResult(!HasUnsavedChanges);
    }
}

Interceptors

public class AuthInterceptor : INavigationInterceptor
{
    public Task OnNavigatingAsync(NavigationContext context)
    {
        if (!_auth.IsLoggedIn)
            throw new OperationCanceledException("Not authenticated.");
        return Task.CompletedTask;
    }

    public Task OnNavigatedAsync(NavigationContext context) => Task.CompletedTask;
}

// Register
services.AddNavigationSupport()
        .RegisterNavigationInterceptor<AuthInterceptor>();

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 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.  net11.0 is compatible. 
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 RoccoZero.AsyncNavigation:

Package Downloads
RoccoZero.AsyncNavigation.Avalonia

A lightweight asynchronous navigation framework based on Microsoft.Extensions.DependencyInjection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.3 114 10/8/2026