Window Management
Quick Reference
csharp
var window = new HermesWindow()
.SetTitle("My App")
.SetSize(1024, 768)
.SetMinSize(640, 480)
.Center()
.SetResizable(true)
.RememberWindowState();Configuration
All configuration methods use a fluent API and must be called before Show() or WaitForClose().
| Method | Description |
|---|---|
SetTitle(string) | Window title |
SetSize(int, int) | Initial size in pixels |
SetPosition(int, int) | Initial position |
Center() | Center on screen |
SetResizable(bool) | Allow resizing |
SetMinSize(int, int) | Minimum size constraint |
SetMaxSize(int, int) | Maximum size constraint |
SetCustomTitleBar(bool) | Enable custom title bar mode |
RememberWindowState(string?) | Persist position, size, and maximized state across launches |
Window State
Control window state at runtime:
csharp
window.MaximizeWindow();
window.MinimizeWindow();
window.RestoreWindow();
window.ToggleMaximize();
bool maximized = window.IsMaximized;Close Request Handling
OnCloseRequested lets you intercept the close button click before the window closes. This is useful for prompting the user about unsaved changes or running cleanup logic.
The handler returns a Task<bool>: return true to allow the close, or false to cancel it.
csharp
var window = new HermesWindow()
.SetTitle("My Editor")
.SetSize(1024, 768)
.OnCloseRequested(async () =>
{
if (!hasUnsavedChanges)
return true;
var shouldClose = await PromptSaveChangesAsync();
return shouldClose;
})
.LoadHtml("<h1>Hello</h1>");
window.WaitForClose();In a Blazor application, you can wire this up from a root component:
razor
@inject HermesWindow Window
@code {
protected override void OnInitialized()
{
Window.OnCloseRequested(OnCloseRequestedAsync);
}
private async Task<bool> OnCloseRequestedAsync()
{
if (!IsDirty)
return true;
ShowConfirmDialog = true;
await InvokeAsync(StateHasChanged);
// Wait for the user's decision
return await _closeDecision.Task;
}
}OnCloseRequested vs OnClosing
OnCloseRequested fires before the window closes and can prevent it. OnClosing fires after the close is confirmed and cannot cancel it. Use OnCloseRequested for save prompts; use OnClosing for final cleanup.
Next Steps
- HermesWindow API - full API reference
- Custom Title Bars - platform-specific title bar behavior
- Dialogs - native file dialogs
