A powerful and flexible navigation framework for Avalonia applications, featuring scoped dependency injection, modular navigation, and MVVM support.
The UXDivers Avalonia Navigation Framework provides a comprehensive solution for building scalable Avalonia applications with:
- Scoped Dependency Injection: Hierarchical service scopes that align with your UI structure
- Outlet-Based Navigation: Navigate between views within defined outlets of your application
- MVVM Support: First-class support for ViewModels with automatic resolution and lifecycle management
- Cross-Platform: Works seamlessly across Desktop, Mobile (iOS/Android), and Browser platforms
- Fluent API: Intuitive builder pattern for configuring navigation and scopes
- Create isolated service scopes for different parts of your application (windows, views, etc.)
- Automatic scope propagation through the visual tree
- Support for custom scope implementations
- Efficient service resolution with parent scope fallback
- Outlet-based navigation with support for multiple outlets per view
- Modal and non-modal navigation
- Navigation parameters and result handling
- View and ViewModel lifecycle awareness (
IActivatable,IInitializeAware) - Nested outlet support
- Compatible with Microsoft.Extensions.DependencyInjection
- Support for both manual service container setup and .NET Generic Host
- Custom view/ViewModel resolution strategies
dotnet add package UXDivers.Popups.MauiIn your App.axaml.cs:
public class App : Application
{
private IServiceProvider? _services;
public override void Initialize()
{
base.Initialize();
AvaloniaXamlLoader.Load(this);
// Create and configure services
var services = new ServiceCollection();
ConfigureServices(services);
// Build and initialize the service provider
_services = services.BuildServiceProvider();
ServiceLocator.Initialize(_services);
}
private void ConfigureServices(IServiceCollection services)
{
// Add navigation support
services.AddNavigation(navigationBuilder =>
{
navigationBuilder.WithDefaultOutlet("MainOutlet");
navigationBuilder.WithNavigationRegistry(registry =>
{
registry.RegisterView<HomeView>()
.WithViewModel<HomeViewModel>()
.AsOutletTarget("MainOutlet");
});
});
// Register your windows
services.AddTransient<MainWindow>();
}
}<Window xmlns="https://github.com/avaloniaui"
xmlns:uxd="https://uxdivers.com"
x:Class="YourApp.MainWindow">
<uxd:Shell uxd:NavigationService.OutletName="MainOutlet" />
</Window>public class HomeViewModel : ViewModelBase
{
private readonly INavigationService _navigationService;
public HomeViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
}
private async Task NavigateToDetails()
{
await _navigationService.NavigateAsync("MainOutlet", "DetailsView");
}
}Detailed documentation is available in the docs folder:
- Scopes Guide - Understanding and configuring scopes
- Navigation Guide - Outlet-based navigation patterns
- Outlet Handlers - Extending navigation to support custom controls
- Service Registration - Registering views, ViewModels, and services
- ServiceLocator: Global access point to the root service provider
- Scopes: Isolated service containers that can be attached to controls
- Outlets: Named navigation targets within your UI
- Navigation Registry: Maps view names to view types and ViewModels
- Behaviors: Extensible hooks for customizing navigation and outlet behavior
Application
├─ ServiceProvider (Global)
│ └─ IScopeRegistry
│
└─ Windows/Views
└─ Scope (Per Window/View)
├─ IOutletManager
├─ INavigationService
└─ INavigationRegistry
- ✅ Windows Desktop
- ✅ macOS Desktop
- ✅ Linux Desktop
- ✅ iOS
- ✅ Android
- ✅ WebAssembly (Browser)
- .NET 8.0 or later
- Avalonia 11.0 or later
- Microsoft.Extensions.DependencyInjection
The repository includes two example applications:
- UXDivers.Avalonia.TestApp - Manual service container setup
- UXDivers.Avalonia.TestAppWithHost - Using .NET Generic Host
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For questions and support, please visit our website or open an issue in the repository.