Skip to content

HermesBlazorAppBuilder

Builder for creating Blazor desktop applications with Hermes.

Creating a Builder

csharp
var builder = HermesBlazorAppBuilder.CreateDefault(args);

Methods

ConfigureWindow

csharp
public HermesBlazorAppBuilder ConfigureWindow(Action<HermesWindowOptions> configure)

Configure the main window options.

csharp
builder.ConfigureWindow(options =>
{
    options.Title = "My App";
    options.Width = 1024;
    options.Height = 768;
    options.CenterOnScreen = true;
    options.DevToolsEnabled = true;
});

Build

csharp
public HermesBlazorApp Build()

Build the application.

Properties

Services

csharp
public IServiceCollection Services { get; }

The service collection for dependency injection.

csharp
builder.Services.AddSingleton<IMyService, MyService>();
builder.Services.AddScoped<IScopedService, ScopedService>();

RootComponents

csharp
public RootComponentCollection RootComponents { get; }

The root Blazor components to add.

csharp
builder.RootComponents.Add<App>("#app");

HermesWindowOptions

Basic Settings

PropertyTypeDescription
TitlestringWindow title
WidthintInitial width
HeightintInitial height
Xint?Initial X position
Yint?Initial Y position
CenterOnScreenboolCenter window when shown

Size Constraints

PropertyTypeDescription
MinWidthint?Minimum width
MinHeightint?Minimum height
MaxWidthint?Maximum width
MaxHeightint?Maximum height

Behavior

PropertyTypeDescription
ResizableboolAllow resizing (default: true)
DevToolsEnabledboolEnable F12 dev tools
ContextMenuEnabledboolEnable right-click context menu
TopMostboolKeep window on top
MaximizedboolStart maximized
MinimizedboolStart minimized

Custom Title Bar

PropertyTypeDescription
CustomTitleBarboolEnable custom title bar mode
ChromelessboolRemove all window chrome

State Persistence

PropertyTypeDescription
WindowStateKeystring?Key for state persistence. Empty string uses title.

HermesBlazorApp

Properties

MainWindow

csharp
public HermesWindow MainWindow { get; }

Access the main window for menu configuration.

Methods

Run

csharp
public void Run()

Run the application (blocking).

DisposeAsync

csharp
public ValueTask DisposeAsync()

Clean up resources.

Complete Example

csharp
using Hermes;
using Hermes.Blazor;
using Microsoft.Extensions.DependencyInjection;

HermesWindow.Prewarm();

var builder = HermesBlazorAppBuilder.CreateDefault(args);

builder.ConfigureWindow(options =>
{
    options.Title = "My Blazor App";
    options.Width = 1024;
    options.Height = 768;
    options.CenterOnScreen = true;
    options.DevToolsEnabled = true;
    options.WindowStateKey = "main";
});

builder.Services.AddSingleton<IAppState, AppState>();

builder.RootComponents.Add<App>("#app");

var app = builder.Build();

app.MainWindow.MenuBar
    .AddMenu("File", file =>
    {
        file.AddItem("Exit", "file.exit", item => item.WithAccelerator("Ctrl+Q"));
    });

app.MainWindow.MenuBar.ItemClicked += itemId =>
{
    if (itemId == "file.exit") app.MainWindow.Close();
};

app.Run();

await app.DisposeAsync();

Released under the Elastic License 2.0