TrailBlazr 0.2.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package TrailBlazr --version 0.2.3
                    
NuGet\Install-Package TrailBlazr -Version 0.2.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="TrailBlazr" Version="0.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TrailBlazr" Version="0.2.3" />
                    
Directory.Packages.props
<PackageReference Include="TrailBlazr" />
                    
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 TrailBlazr --version 0.2.3
                    
#r "nuget: TrailBlazr, 0.2.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 TrailBlazr@0.2.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=TrailBlazr&version=0.2.3
                    
Install as a Cake Addin
#tool nuget:?package=TrailBlazr&version=0.2.3
                    
Install as a Cake Tool

TrailBlazr

CI CD NuGet License: MIT

TrailBlazr is a powerful library for Blazor that enables compile-correct view management with linked ViewModels through the MVVM pattern. It provides a seamless navigation system using a view container component and view manager, making it easy to build maintainable Blazor applications with strong typing and separation of concerns.

Features

  • 🔗 Strongly-typed View-ViewModel binding - Compile-time safety for view-viewmodel relationships
  • 🧭 Navigation management - Centralized view navigation through IViewManager
  • 🏗️ MVVM pattern support - Clean separation of concerns with ViewModels
  • 📦 Dependency injection integration - Seamless integration with .NET DI container
  • 🎯 Dynamic view rendering - Efficient view switching with ViewContainer component
  • Minimal setup - Easy configuration with extension methods

Installation

Install TrailBlazr via NuGet Package Manager:

dotnet add package TrailBlazr

Or via Package Manager Console:

Install-Package TrailBlazr

Quick Start

1. Register TrailBlazr services

In your Program.cs or startup configuration:

using TrailBlazr.Extensions;

// Add TrailBlazr services
builder.Services.AddTrailBlazr();

// Register your views and viewmodels
builder.Services.RegisterView<HomeView, HomeViewModel>();
builder.Services.RegisterView<UserProfileView, UserProfileViewModel>();

var app = builder.Build();

2. Create a ViewModel

using TrailBlazr.ViewModels;

public class HomeViewModel : ViewModelBase<HomeViewModel, HomeView>
{
    public string Title { get; set; } = "Welcome to TrailBlazr!";
    public string Message { get; set; } = "Navigate with confidence.";
}

3. Create a View

@using TrailBlazr.Views
@inherits ViewBase<HomeView, HomeViewModel>

<div class="home-container">
    <h1>@ViewModel.Title</h1>
    <p>@ViewModel.Message</p>
    
    <button @onclick="() => NavigateToProfile()">
        Go to Profile
    </button>
</div>

@code {
    [Inject]
    private IViewManager ViewManager { get; set; }

    private void NavigateToProfile()
    {
        this.ViewManager.ShowView<UserProfileView>();
    }
}

4. Add ViewContainer to your layout

@using TrailBlazr.Components

<div class="main-content">
    <ViewContainer />
</div>

5. Navigate between views

Inject IViewManager anywhere in your application to navigate:

[Inject]
private IViewManager ViewManager { get; set; }

// Navigate to a view with optional parameters
ViewManager.ShowView<UserProfileView>([ {"user", userId} ]);

// Or navigate by type
ViewManager.ShowView(typeof(HomeView), [ {"user", userId} ]);

// Or navigate by path
ViewManager.ShowView("/user/profile", [ {"user", userId} ]);

Core Concepts

ViewBase<TView, TViewModel>

Base class for all views that provides:

  • Strong typing between view and viewmodel
  • Automatic viewmodel injection
  • Access to ViewManager for navigation

ViewModelBase<TViewModel, TView>

Base class for all viewmodels that provides:

  • Strong typing between viewmodel and view
  • Foundation for implementing business logic
  • Inherits from INotifyPropertyChanged for data binding

IViewManager

Central service for managing view navigation:

  • ShowView<TView>(RouteValues? routeValues) - Navigate with strong typing
  • ShowView(Type viewType, RouteValues? routeValues) - Navigate by type
  • ShowView(string path, RouteValues? routeValues) - Navigate by path
  • ShowViewRequested event - Subscribe to navigation events

ViewContainer

Blazor component that hosts and renders the current view:

  • Automatically updates when navigation occurs
  • Supports dynamic component rendering
  • Passes data context to views
  • Hooks into NavigationManager to handle URL changes and forwards navigation requests to IViewManager

Architecture

TrailBlazr follows the MVVM (Model-View-ViewModel) pattern:

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│      View       │◄──►│    ViewModel     │◄──►│     Model       │
│   (Razor)       │    │   (C# Class)     │    │   (Data)        │
└─────────────────┘    └──────────────────┘    └─────────────────┘
         ▲                        ▲
         │                        │
         ▼                        ▼
┌─────────────────┐    ┌──────────────────┐
│  ViewContainer  │◄──►│   ViewManager    │
│  (Component)    │    │   (Service)      │
└─────────────────┘    └──────────────────┘

Requirements

  • .NET 9.0 or later
  • Blazor Hybrid or Blazor Server/WebAssembly
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
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
0.3.0 154 9/1/2025
0.2.9 152 8/10/2025
0.2.8 231 8/5/2025
0.2.7 230 8/5/2025
0.2.6 200 8/4/2025
0.2.5 94 8/3/2025
0.2.4 90 8/3/2025
0.2.3 53 8/2/2025
0.2.2 59 8/1/2025
0.2.1 68 8/1/2025
0.2.0 62 8/1/2025
0.1.0 79 8/1/2025