NavigationFrame.Avalonia
1.4.0
See the version list below for details.
dotnet add package NavigationFrame.Avalonia --version 1.4.0
NuGet\Install-Package NavigationFrame.Avalonia -Version 1.4.0
<PackageReference Include="NavigationFrame.Avalonia" Version="1.4.0" />
<PackageVersion Include="NavigationFrame.Avalonia" Version="1.4.0" />
<PackageReference Include="NavigationFrame.Avalonia" />
paket add NavigationFrame.Avalonia --version 1.4.0
#r "nuget: NavigationFrame.Avalonia, 1.4.0"
#:package NavigationFrame.Avalonia@1.4.0
#addin nuget:?package=NavigationFrame.Avalonia&version=1.4.0
#tool nuget:?package=NavigationFrame.Avalonia&version=1.4.0
NavigationFrame.Avalonia
A flexible and layout-aware navigation framework for Avalonia UI, inspired by Blazor's layout system. It supports transition animations, navigation history, and MVVM patterns.
Features
- Layout Support: Define shared layouts (like Master/Detail, Shells) that wrap your pages.
- MVVM Ready:
IPageContextandILayoutContextinterfaces for ViewModel integration. - Navigation Stack: Built-in Forward/Back navigation history.
- Transitions: Built-in transition animations (Slide, DrillIn, Entrance, Suppress) and support for custom transitions.
- Navigation Awareness: Events for
OnNavigatedTo,OnNavigatingAway(cancellable), andOnNavigatedAway.
Installation
Install the NuGet package:
dotnet add package NavigationFrame.Avalonia
Getting Started
1. Add Resources
In your App.axaml, add the required resources to Application.Resources:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://NavigationFrame.Avalonia/Styling/Resources.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
2. Define a Layout (Optional)
Create a layout control by implementing ILayoutControl. This control acts as a wrapper for your pages.
View (MainLayout.axaml):
<UserControl xmlns="https://github.com/avaloniaui"
x:Class="MyApp.Views.MainLayout">
<DockPanel>
<TextBlock Text="My App Header" DockPanel.Dock="Top"/>
<ContentPresenter x:Name="BodyHolder" DockPanel.Dock="Bottom"/>
</DockPanel>
</UserControl>
Code-behind (MainLayout.axaml.cs):
using Avalonia.Controls;
using NavigationFrame.Avalonia;
public partial class MainLayout : UserControl, ILayoutControl
{
public MainLayout()
{
InitializeComponent();
}
public Control GetBodyHolder()
{
return this.FindControl<ContentPresenter>("BodyHolder")!;
}
public void OnBodyChanged(Control currentBody)
{
// Optional: React when the page changes
}
}
ViewModel (MainLayoutViewModel.cs):
using NavigationFrame.Avalonia;
public class MainLayoutViewModel : ILayoutContext
{
public INavigationService? NavigationService { get; set; }
public void OnBodyChanged(IPageContext pageContext)
{
// Update title or other properties based on the current page
Console.WriteLine($"Switched to page: {pageContext.Title}");
}
}
3. Define a Page
Create a page and optionally link it to a layout.
View (HomePage.axaml):
<UserControl xmlns="https://github.com/avaloniaui"
x:Class="MyApp.Views.HomePage">
<StackPanel>
<TextBlock Text="Welcome to Home Page!" />
<Button Content="Go to Settings" Command="{Binding GoSettingsCommand}" />
</StackPanel>
</UserControl>
ViewModel (HomePageViewModel.cs):
using CommunityToolkit.Mvvm.Input; // Example
using NavigationFrame.Avalonia;
// Link this page to MainLayoutViewModel
[LayoutContext(typeof(MainLayoutViewModel))]
public partial class HomePageViewModel : IPageContext
{
public INavigationService? NavigationService { get; set; }
public string Title => "Home";
[RelayCommand]
private async Task GoSettings()
{
// Navigate to SettingsPageViewModel
await NavigationService!.NavigateAsync(typeof(SettingsPageViewModel));
}
}
4. Setup ViewFactory
You need an IViewFactory to resolve Views from ViewModels (or keys).
using Avalonia.Controls;
using NavigationFrame.Avalonia;
public class ViewFactory : IViewFactory
{
public Control ResolveView(object obj)
{
// Simple example: mapping Types to Views
if (obj is Type type)
{
if (type == typeof(HomePageViewModel)) return new HomePage();
if (type == typeof(MainLayoutViewModel)) return new MainLayout();
// ...
}
return new TextBlock { Text = "View Not Found" };
}
}
5. Setup LayoutAwareFrame
In your main window or view, place the LayoutAwareFrame.
<Window xmlns:nav="using:NavigationFrame.Avalonia">
<nav:LayoutAwareFrame x:Name="NavFrame" />
</Window>
Code-behind (MainWindow.axaml.cs):
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var frame = this.FindControl<LayoutAwareFrame>("NavFrame");
frame.ViewFactory = new ViewFactory(); // Set your factory
// Navigate to the initial page
frame.NavigateAsync(typeof(HomePageViewModel));
}
}
Navigation
- Navigate:
NavigateAsync(object key, object? parameter = null) - Go Back:
GoBackAsync() - Go Forward:
GoForwardAsync()
Transitions
You can specify transitions during navigation:
await NavigationService.NavigateAsync(
typeof(DetailsViewModel),
transition: Transition.DrillIn
);
Available transitions:
SlideFromRight(Default)SlideFromLeftSlideFromTopSlideFromBottomDrillInEntranceSuppress(No animation)
Lifecycle Events
Implement IPageContext in your ViewModel to handle lifecycle events:
OnNavigatedTo(NavigationEventArgs e)OnNavigatingAway(NavigatingCancelEventArgs e): Can cancel navigation.OnNavigatedAway(NavigationEventArgs e)OnPageReleased(): Called when page is removed from history stack.
| 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 | 120 | 12/31/2025 | |
| 2.0.6 | 117 | 12/31/2025 | |
| 2.0.5 | 122 | 12/30/2025 | |
| 2.0.4 | 116 | 12/29/2025 | |
| 2.0.3 | 117 | 12/28/2025 | |
| 2.0.2 | 120 | 12/28/2025 | |
| 2.0.0 | 132 | 12/27/2025 | |
| 1.9.9 | 208 | 12/24/2025 | |
| 1.9.8.1 | 191 | 12/22/2025 | |
| 1.9.8 | 272 | 12/22/2025 | |
| 1.9.6 | 153 | 12/20/2025 | |
| 1.9.0 | 248 | 12/14/2025 | |
| 1.7.0 | 230 | 12/12/2025 | |
| 1.6.0 | 534 | 12/10/2025 | |
| 1.5.1 | 450 | 12/8/2025 | |
| 1.5.0 | 442 | 12/8/2025 | |
| 1.4.0 | 567 | 12/7/2025 |