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
| Property | Type | Description |
|---|---|---|
Title | string | Window title |
Width | int | Initial width |
Height | int | Initial height |
X | int? | Initial X position |
Y | int? | Initial Y position |
CenterOnScreen | bool | Center window when shown |
Size Constraints
| Property | Type | Description |
|---|---|---|
MinWidth | int? | Minimum width |
MinHeight | int? | Minimum height |
MaxWidth | int? | Maximum width |
MaxHeight | int? | Maximum height |
Behavior
| Property | Type | Description |
|---|---|---|
Resizable | bool | Allow resizing (default: true) |
DevToolsEnabled | bool | Enable F12 dev tools |
ContextMenuEnabled | bool | Enable right-click context menu |
TopMost | bool | Keep window on top |
Maximized | bool | Start maximized |
Minimized | bool | Start minimized |
Custom Title Bar
| Property | Type | Description |
|---|---|---|
CustomTitleBar | bool | Enable custom title bar mode |
Chromeless | bool | Remove all window chrome |
State Persistence
| Property | Type | Description |
|---|---|---|
WindowStateKey | string? | 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();