Skip to content

ArchLeaders/Avalonia.MenuFactory

Repository files navigation

Avalonia.MenuFactory

NuGet NuGet

Avalonia Menu Factory is a dynamic UI library that lets you seamlessly implement and manage a menu bar in your Avalonia application from only a class, where each function is a menu item.

Usage

Avalonia Menu Factory works by reading a decorated class of methods and sending the results into an Menu control.

Use the static MenuFactory.Generate() method, passing in an instance of your menu class to create the menu items. These items can then be assigned to the Menu.Items property.

MenuRoot = this.FindControl<Menu>("MenuRoot")!;

MenuModel menuModel = new();
MenuRoot.Items = MenuFactory.Generate(menuModel);

To build your menu class, decorate each method with the Avalonia.MenuFactory.MenuAttribute attribute where you can specify the MenuItem name, navigation path (e.g. About/Help for About > Help > {method}), icon, and hotkey.

[Menu("Exit", "_File", Icon = MaterialIconKind.ExitToApp, HotKey = "Alt + F4")]
public static void Exit()
{
    Environment.Exit(0);
}

[Menu("Readme", "_About/Help", Icon = MaterialIconKind.HelpOutline)]
public static void Readme()
{
    Debug.WriteLine(File.ReadAllText("../ReadMe.md"));
    // ...
}

[Menu("Credits", "_About", Icon = MaterialIconKind.PersonCheck)]
public static async void Credits()
{
    Debug.WriteLine(File.ReadAllText("../Credits.md"));
    // ...
}

The previous two examples will build the following menu:

Install

Install with NuGet or build from source.

NuGet

Install-Package AvaloniaMenuFactory

Build from Source

git clone https://github.com/ArchLeaders/Avalonia.MenuFactory.git
dotnet build Avalonia.MenuFactory

© 2022 Arch Leaders

About

Dynamic UI library that lets you seamlessly implement a menu bar into your Avalonia application using only a class, where each function is a menu item.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages