forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Overview
github-actions[bot] edited this page Oct 15, 2025
·
2 revisions
The ElectronNET.Core API provides comprehensive access to Electron's native desktop functionality through a .NET interface. This section documents all the available API classes and their methods, events, and usage patterns.
- Electron.App - Control your application's event lifecycle, manage app metadata, and handle system-level operations
- Electron.WindowManager - Create and manage browser windows, control window behavior and appearance
- Electron.Menu - Create application menus, context menus, and menu items with full keyboard shortcut support
- Electron.Dialog - Display native system dialogs for opening/saving files, showing messages and alerts
- Electron.Notification - Show native desktop notifications with custom content and actions
- Electron.Tray - Create system tray icons with context menus and tooltip support
- Electron.Dock - macOS dock integration for bounce effects and badge counts
- Electron.Shell - Desktop integration for opening files, URLs, and accessing system paths
- Electron.Clipboard - Read from and write to the system clipboard with multiple data formats
- Electron.Screen - Access display and screen information for responsive layouts
- Electron.NativeTheme - Detect and respond to system theme changes (light/dark mode)
- Electron.IpcMain - Inter-process communication between main process and renderer processes
- Electron.HostHook - Custom host hook functionality for advanced integration scenarios
- Electron.GlobalShortcut - Register global keyboard shortcuts that work even when app is not focused
- Electron.AutoUpdater - Handle application updates and installation processes
- Electron.PowerMonitor - Monitor system power events like sleep, wake, and battery status
// Handle app startup
Electron.App.Ready += () =>
{
Console.WriteLine("App is ready!");
};
// Handle window management
Electron.App.WindowAllClosed += () =>
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Electron.App.Quit();
}
};// Create main window
var mainWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
Width = 1200,
Height = 800,
Show = false,
WebPreferences = new WebPreferences
{
NodeIntegration = false,
ContextIsolation = true
}
});
// Load content
await mainWindow.WebContents.LoadURLAsync("https://example.com");
// Show when ready
mainWindow.OnReadyToShow += () => mainWindow.Show();// Show open file dialog
var mainWindow = Electron.WindowManager.BrowserWindows.First();
var result = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, new OpenDialogOptions
{
Properties = new[] { OpenDialogProperty.OpenFile },
Filters = new[]
{
new FileFilter { Name = "Text Files", Extensions = new[] { "txt" } }
}
});
if (result.Length > 0)
{
Console.WriteLine($"Selected file: {result[0]}");
}// Open file with default application
Electron.Shell.OpenPathAsync(filePath);
// Show item in file manager
Electron.Shell.ShowItemInFolderAsync(filePath);
// Open external URL
Electron.Shell.OpenExternalAsync("https://electron.net");All Electron APIs are asynchronous and return Task or Task<T>:
// ✅ Correct - await async operations
var result = await Electron.Dialog.ShowOpenDialogAsync(window, options);
// ❌ Incorrect - blocking call
var result = Electron.Dialog.ShowOpenDialogAsync(window, options).Result;Use proper event subscription patterns:
// ✅ Correct - proper event subscription
Electron.App.WindowAllClosed += () =>
{
Electron.App.Quit();
};
// ❌ Incorrect - missing null check
Electron.App.WindowAllClosed(); // This would throwAlways handle potential errors:
try
{
var result = await Electron.Dialog.ShowSaveDialogAsync(window, options);
if (!string.IsNullOrEmpty(result))
{
// Process the selected file path
}
}
catch (Exception ex)
{
// Handle dialog errors
Console.WriteLine($"Dialog error: {ex.Message}");
}- Use
BrowserWindowinstances as parent windows for dialogs - Dialogs automatically become modal when parent window is provided
- Window events coordinate with application lifecycle events
-
IpcMainhandles communication from renderer processes - Use with
Electron.WindowManagerfor window-specific messaging - Coordinate with
Electron.Appevents for application-wide communication
-
Shelloperations work with file paths fromDialogoperations -
Screeninformation helps create properly sized windows -
NotificationandTrayprovide complementary user interaction methods
- Electron.App - Start with application lifecycle management
- Electron.WindowManager - Learn window creation and management
- Electron.Dialog - Add file operations and user interactions
- Electron.Menu - Implement application menus and shortcuts
- Electron Documentation - Official Electron API reference
- Getting Started - Development setup guides
- Migration Guide - Moving from previous versions
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.