NavigationFrame.Avalonia
1.5.1
See the version list below for details.
dotnet add package NavigationFrame.Avalonia --version 1.5.1
NuGet\Install-Package NavigationFrame.Avalonia -Version 1.5.1
<PackageReference Include="NavigationFrame.Avalonia" Version="1.5.1" />
<PackageVersion Include="NavigationFrame.Avalonia" Version="1.5.1" />
<PackageReference Include="NavigationFrame.Avalonia" />
paket add NavigationFrame.Avalonia --version 1.5.1
#r "nuget: NavigationFrame.Avalonia, 1.5.1"
#:package NavigationFrame.Avalonia@1.5.1
#addin nuget:?package=NavigationFrame.Avalonia&version=1.5.1
#tool nuget:?package=NavigationFrame.Avalonia&version=1.5.1
NavigationFrame.Avalonia
A flexible and powerful navigation framework for Avalonia UI that supports Layouts (similar to Blazor/ASP.NET Core), built-in Transitions, and MVVM-friendly lifecycle events.
Features
- Layout Support: Define common layouts (e.g., Master-Detail, Sidebar) and wrap your pages automatically.
- Navigation History: Built-in support for Back and Forward navigation stacks.
- Caching: Configurable page caching to preserve state.
- Transitions: A wide variety of built-in animations (Slide, DrillIn, Entrance, Zoom).
- MVVM Friendly: Lifecycle interfaces for both Views (
IPageControl) and ViewModels (IPageContext). - Async Navigation: Fully asynchronous navigation pipeline.
Getting Started
1. Add Resources
You must add the framework's resources to your App.axaml to ensure controls render correctly.
<Application ...>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://NavigationFrame.Avalonia/Styling/Resources.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
2. Implement IViewFactory
You need to tell the framework how to resolve your Views (Controls).
using NavigationFrame.Avalonia;
using Avalonia.Controls;
public class ViewFactory : IViewFactory
{
public Control ResolveView(object key)
{
if (key is Type type)
{
var control = (Control)Activator.CreateInstance(type)!;
control.DataContext = CreateViewModelForView(type);
return control;
}
// Handle other key types or dependency injection here
throw new ArgumentException($"Cannot resolve view for key {key}");
}
private object CreateViewModelForView(Type viewType)
{
// Use your DI container or create instance manually
throw new NotImplementedException();
}
}
3. Setup LayoutAwareFrame
Add the LayoutAwareFrame to your main window or view.
<Window xmlns:nav="using:NavigationFrame.Avalonia" ...>
<nav:LayoutAwareFrame x:Name="AppFrame" />
</Window>
In your code-behind (or setup logic), initialize the dependencies:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// 1. Setup Navigation Service
var navService = new DefaultNavigationService();
// 2. Setup View Factory
var viewFactory = new ViewFactory(); // Your implementation
// 3. Configure Frame, binding supported
AppFrame.NavigationService = navService;
AppFrame.ViewFactory = viewFactory;
// 4. Navigate to Home
AppFrame.NavigateAsync(typeof(HomePage));
}
}
Usage
Navigation
Inject INavigationService into your ViewModels or access it from the Frame.
// Simple navigation
await _navService.NavigateAsync(typeof(DetailsPage));
// Navigation with Parameter
await _navService.NavigateAsync(typeof(DetailsPage), "MyParameter");
// Navigation with Transition
await _navService.NavigateAsync(typeof(DetailsPage), null, Transition.SlideFromRight);
// Go Back
await _navService.GoBackAsync();
Lifecycle Events
For ViewModels (IPageContext)
Implement IPageContext in your ViewModel to handle navigation events.
public class MyPageViewModel : IPageContext
{
// Injected automatically
// make sure you set the ViewModel as DataContext when ResolveView is called.
public INavigationService NavigationService { get; set; }
// Load data here (already in background thread)
public async Task OnNavigatingTo(PageNavigationArgs args)
{
if (args.Parameter is string id)
{
await LoadDataAsync(id);
}
}
public Task<bool> OnNavigatingAway(PageNavigationArgs args)
{
// Return true to cancel navigation (e.g., unsaved changes)
return Task.FromResult(false);
}
public Task OnNavigatedAway(PageNavigationArgs args)
{
// Indicates that the page is no longer visible, useful to stop some background tasks.
return Task.CompletedTask;
}
public void OnPageReleased()
{
// Final cleanup when removed from cache/stack
}
}
For Views (IPageControl)
Implement IPageControl in your UserControl code-behind if you need UI-specific lifecycle events.
Layouts
Layouts allow you to define a common shell (like a header or sidebar) for multiple pages.
- Create a Layout Control: Implement
ILayoutControl.
public partial class MainLayout : UserControl, ILayoutControl
{
public Control GetBodyHolder()
{
// Return the container where the page content should be placed
return this.FindControl<ContentPresenter>("BodyArea");
}
public void OnBodyChanged(Control currentBody)
{
// Optional: React to body change
}
}
Assign Layout to Page:
Option A: Attribute
[LayoutContext(typeof(MainLayout))] public class HomePageViewModel : IPageContext { ... }Option B: Implement Interface
public class HomePageViewModel : IPageContext { public Type? GetLayoutContextType() => typeof(MainLayout); // ... }
Key Components
- LayoutAwareFrame: The core control handling navigation, history, and layouts.
- INavigationService: The interface used to request navigation.
- IViewFactory: The bridge between navigation keys (Types) and actual UI Controls.
- IPageContext: ViewModel interface for navigation lifecycle.
- ILayoutControl: Interface for creating Layout shells.
Contact
For questions or support, please reach out to richardplus@foxmail.com
| Product | Versions 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. |
-
net10.0
- Avalonia (>= 11.3.8)
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 | |
|---|---|---|---|
| 2.0.7 | 150 | 12/31/2025 | |
| 2.0.6 | 144 | 12/31/2025 | |
| 2.0.5 | 145 | 12/30/2025 | |
| 2.0.4 | 141 | 12/29/2025 | |
| 2.0.3 | 144 | 12/28/2025 | |
| 2.0.2 | 142 | 12/28/2025 | |
| 2.0.0 | 158 | 12/27/2025 | |
| 1.9.9 | 231 | 12/24/2025 | |
| 1.9.8.1 | 216 | 12/22/2025 | |
| 1.9.8 | 293 | 12/22/2025 | |
| 1.9.6 | 176 | 12/20/2025 | |
| 1.9.0 | 267 | 12/14/2025 | |
| 1.7.0 | 261 | 12/12/2025 | |
| 1.6.0 | 557 | 12/10/2025 | |
| 1.5.1 | 472 | 12/8/2025 | |
| 1.5.0 | 466 | 12/8/2025 | |
| 1.4.0 | 585 | 12/7/2025 |