Lemon.ModuleNavigation.Avaloniaui
2.0.2-beta
See the version list below for details.
dotnet add package Lemon.ModuleNavigation.Avaloniaui --version 2.0.2-beta
NuGet\Install-Package Lemon.ModuleNavigation.Avaloniaui -Version 2.0.2-beta
<PackageReference Include="Lemon.ModuleNavigation.Avaloniaui" Version="2.0.2-beta" />
<PackageVersion Include="Lemon.ModuleNavigation.Avaloniaui" Version="2.0.2-beta" />
<PackageReference Include="Lemon.ModuleNavigation.Avaloniaui" />
paket add Lemon.ModuleNavigation.Avaloniaui --version 2.0.2-beta
#r "nuget: Lemon.ModuleNavigation.Avaloniaui, 2.0.2-beta"
#:package Lemon.ModuleNavigation.Avaloniaui@2.0.2-beta
#addin nuget:?package=Lemon.ModuleNavigation.Avaloniaui&version=2.0.2-beta&prerelease
#tool nuget:?package=Lemon.ModuleNavigation.Avaloniaui&version=2.0.2-beta&prerelease
Lemon.ModuleNavigation
<p align="center"> <img src="https://github.com/NeverMorewd/Lemon.ModuleNavigation/blob/master/src/Lemon.ModuleNavigation.Sample/Assets/lemon-100.png" /> </p>
Language
English
Introduction
Lemon.ModuleNavigation
A lightweight module navigation framework built on top of the Microsoft Dependency Injection (MSDI) for AvaloniaUI, WPF and .net-xaml-platforms else. Support native aot (Avaloniaui)
Lemon.ModuleNavigation.AvaloniaUI
Extending Lemon.ModuleNavigation, this package provides handy NavigationContainers specifically designed for AvaloniaUI.
Key Advantages:
- Lightweight: Minimal performance overhead.
- Commonly module options are provided:LoadonDemand; Unload; Multi-Instance.
- Few dependencies: Only relies on
Microsoft.Extensions.DependencyInjection.Abstractions. - Framework Agnostic: Does not enforce any specific MVVM framework, allowing developers to use the MVVM framework of their choice.
- Highly Extensible: Easily customizable to suit specific needs.
- Simple to Use.
ModuleNavigation screenshot:
ViewNavigation screenshot:
Usage:
Create module with View and ViewModel
Module.cs
using System;
using Lemon.ModuleNavigation.Avaloniaui;
namespace Lemon.ModuleNavigation.Sample.ModuleAs
{
public class ModuleA : AvaModule<ViewA, ViewModelA>
{
public ModuleA(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
/// <summary>
/// Specifies whether this module needs to be loaded on demand
/// Default value is True
/// </summary>
public override bool LoadOnDemand => false;
/// <summary>
/// Alias of module for displaying usually
/// Default value is class name of Module
/// </summary>
public override string? Alias => base.Alias;
/// <summary>
/// Specifies whether this module allow multiple instances
/// If true,every navigation to this module will generate a new instance.
/// Default value is false.
/// </summary>
public override bool ForceNew => base.ForceNew;
/// <summary>
/// Specifies whether this module can be unloaded.
/// Default value is false.
/// </summary>
public override bool CanUnload => base.CanUnload;
/// <summary>
/// Initialize
/// </summary>
public override void Initialize()
{
base.Initialize();
}
}
}
View.cs
using Avalonia.Controls;
using Lemon.ModuleNavigation.Abstracts;
namespace Lemon.ModuleNavigation.Sample.ModuleAs;
public partial class ViewA : UserControl, IView
{
public ViewA()
{
InitializeComponent();
}
}
ViewModel.cs
using Lemon.ModuleNavigation.Abstracts;
using Lemon.ModuleNavigation.Sample.ViewModels;
using System;
namespace Lemon.ModuleNavigation.Sample.ModuleAs
{
public class ViewModelA : IViewModel
{
public void Dispose()
{
}
}
}
In MainView.axaml or MainWindow.axaml
ContentControl
<ContentControl lm:NavigationExtension.ModuleContainerName="NContentControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" />
TabControl
<TabControl lm:NavigationExtension.ModuleContainerName="NTabControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" >
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="2">
<TextBlock Text="{Binding Alias}" />
<Button lm:NavigationExtension.CanUnload="{Binding CanUnload}"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding View}" />
</DataTemplate>
</TabControl.ContentTemplate>
</NTabContainer>
MainViewModel.cs
public class MainViewModel : ViewModelBase, IServiceAware
{
private readonly NavigationService _navigationService;
private readonly IServiceProvider _serviceProvider;
private readonly IDialogService _dialogService;
private readonly ILogger _logger;
public MainViewModel(IEnumerable<IModule> modules,
IServiceProvider serviceProvider,
NavigationService navigationService,
IDialogService dialogService,
ILogger<MainViewModel> logger)
{
_logger = logger;
_navigationService = navigationService;
_serviceProvider = serviceProvider;
_dialogService = dialogService;
Modules = new ObservableCollection<IModule>(modules);
}
/// <summary>
/// IServiceAware
/// <summary>
public IServiceProvider ServiceProvider => _serviceProvider;
/// <summary>
/// Navigation is triggered based on the timing of the customization
/// </summary>
public void OnSelectedModuleChanged(IModule? selectedModule)
{
_navigationService.NavigateTo(selectedModule!);
}
/// <summary>
/// For binding
/// </summary>
public ObservableCollection<IModule> Modules
{
get;
set;
}
}
With generic host. Using Lemon.Hosting.AvaloniaUIDesktop
Program.cs in Lemon.ModuleNavigation.Sample.DesktopHosting
class Program
{
[STAThread]
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public static void Main(string[] args)
{
var hostBuilder = Host.CreateApplicationBuilder();
// module navigation
hostBuilder.Services.AddAvaNavigationSupport();
// modules
hostBuilder.Services.AddModule<ModuleA>();
hostBuilder.Services.AddModule<ModuleB>();
hostBuilder.Services.AddModule<ModuleC>();
// views
hostBuilder.Services.AddView<ViewAlpha, ViewAlphaViewModel>(nameof(ViewAlpha));
hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewAlpha));
hostBuilder.Services.AddAvaloniauiDesktopApplication<App>(BuildAvaloniaApp);
hostBuilder.Services.AddMainWindow<MainWindow, MainViewModel>();
var appHost = hostBuilder.Build();
appHost.RunAvaloniauiApplication<MainWindow>(args);
}
public static AppBuilder BuildAvaloniaApp(AppBuilder appBuilder)
{
return appBuilder
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseReactiveUI();
}
}
Without generic host
AppWithDI.xaml.cs in Lemon.ModuleNavigation.Sample
public partial class AppWithDI : Application
{
private IServiceProvider? _serviceProvider;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
var services = new ServiceCollection();
services.AddNavigationContext()
.AddModule<ModuleA>()
.AddSingleton<MainWindow>()
.AddSingleton<MainView>()
.AddSingleton<MainViewModel>();
_serviceProvider = services.BuildServiceProvider();
var viewModel = _serviceProvider.GetRequiredService<MainViewModel>();
switch (ApplicationLifetime)
{
case IClassicDesktopStyleApplicationLifetime desktop:
var window = _serviceProvider.GetRequiredService<MainWindow>();
window.DataContext = viewModel;
desktop.MainWindow = window;
break;
case ISingleViewApplicationLifetime singleView:
var view = _serviceProvider.GetRequiredService<MainView>();
view.DataContext = viewModel;
singleView.MainView = view;
break;
}
base.OnFrameworkInitializationCompleted();
}
}
Lemon.Extensions.ModuleNavigation.Sample.Desktop
A sample desktop application for Lemon.ModuleNavigation and Lemon.ModuleNavigation.AvaloniaUI.
Lemon.Extensions.ModuleNavigation.Sample.DesktopHosting
A sample desktop application for Lemon.ModuleNavigation and Lemon.ModuleNavigation.AvaloniaUI using AvaloniaUI.
It introduces Lemon.Hosting.AvaloniaUIDesktop to support .NET Generic Host.
AOT config:
Update .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<PublishAot>true</PublishAot>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
...
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsTrimmable>true</IsTrimmable>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<RdXmlFile Include="rd.xml" />
</ItemGroup>
</Project>
Add rd.xml
<Directives>
<Application>
<Assembly Name="Lemon.ModuleNavigation.Sample" Dynamic="Required All"/>
<Assembly Name="Lemon.ModuleNavigation.Avaloniaui" Dynamic="Required All"/>
<Assembly Name="Lemon.ModuleNavigation" Dynamic="Required All"/>
</Application>
</Directives>
Lemon.Toolkit
This is a practical application of Lemon.ModuleNavigation. It is a collection of toolkits for clients based on Semi-Avaloniaui, Lemon.Hosting.AvaloniaUIDesktop, and Lemon.ModuleNavigation. As of now, it includes:
- Module navigation based on NTabContainer
- Custom HomeModule
- Custom console log
- File Inspector (ongoing)
- File Comparer (ongoing)
- ...
中文
简介
Lemon.ModuleNavigation
Lemon.ModuleNavigation 是一个基于微软依赖注入(MSDI)的轻量级模块导航框架,专为 AvaloniaUI、WPF 和其他 .NET XAML 平台设计。它支持 Native AOT,为 AvaloniaUI 提供高效的导航,性能开销极低。
Lemon.ModuleNavigation.AvaloniaUI
Lemon.ModuleNavigation 的扩展包,专为 AvaloniaUI 提供特定的 NavigationContainers,使得模块导航更加无缝且灵活。
主要优势:
- 轻量级:最小的性能开销。
- 依赖少:只依赖
Microsoft.Extensions.DependencyInjection.Abstractions。 - 框架无关:不强制使用任何特定的 MVVM 框架,允许开发者选择自己喜欢的 MVVM 框架。
- 高度可扩展:可以轻松定制以满足特定需求。
- 简单易用。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 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. |
-
net6.0
- Avalonia (>= 11.1.1)
- Lemon.ModuleNavigation (>= 2.0.2-beta)
-
net8.0
- Avalonia (>= 11.1.1)
- Lemon.ModuleNavigation (>= 2.0.2-beta)
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.2.1 | 163 | 7/28/2025 | |
| 2.2.0 | 228 | 7/28/2025 | |
| 2.1.2-rc | 201 | 4/10/2025 | |
| 2.1.1-rc | 183 | 4/2/2025 | |
| 2.1.0-rc | 126 | 3/29/2025 | |
| 2.0.9-beta | 139 | 2/14/2025 | |
| 2.0.8-beta | 139 | 2/9/2025 | |
| 2.0.7-beta | 171 | 12/14/2024 | |
| 2.0.6-beta | 135 | 12/9/2024 | |
| 2.0.5-beta | 130 | 11/17/2024 | |
| 2.0.4-beta | 114 | 11/17/2024 | |
| 2.0.3-beta | 169 | 11/14/2024 | |
| 2.0.2-beta | 131 | 11/13/2024 | |
| 2.0.1-beta | 133 | 11/12/2024 | |
| 2.0.0-beta | 116 | 11/10/2024 | |
| 1.0.1 | 203 | 10/15/2024 | |
| 1.0.0 | 180 | 10/11/2024 |