Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 744
WindowManager
Create and manage browser windows, control window behavior and appearance.
The Electron.WindowManager API provides comprehensive control over browser windows in your Electron application. It handles window creation, management, and coordination with the application lifecycle.
Gets a read-only collection of all currently open browser views.
Gets a read-only collection of all currently open browser windows.
Controls whether the application quits when all windows are closed. Default is true.
Creates a new browser view with default options.
Returns:
The created BrowserView instance.
Creates a new browser view with custom options.
Parameters:
options- Browser view configuration options
Returns:
The created BrowserView instance.
Creates a new browser window with default options.
Parameters:
loadUrl- URL to load in the window. Defaults to "http://localhost"
Returns:
The created BrowserWindow instance.
🧊 Task<BrowserWindow> CreateWindowAsync(BrowserWindowOptions options, string loadUrl = "http://localhost")
Creates a new browser window with custom options.
Parameters:
options- Window configuration optionsloadUrl- URL to load in the window. Defaults to "http://localhost"
Returns:
The created BrowserWindow instance.
// Create window with default optionsvarmainWindow=awaitElectron.WindowManager.CreateWindowAsync();// Create window with custom optionsvarsettingsWindow=awaitElectron.WindowManager.CreateWindowAsync(newBrowserWindowOptions{Width=800,Height=600,Show=false,Title="Settings",WebPreferences=newWebPreferences{NodeIntegration=false,ContextIsolation=true}},"https://localhost:5001/settings");// Get all windowsvarwindows=Electron.WindowManager.BrowserWindows;Console.WriteLine($"Open windows: {windows.Count}");// Configure quit behaviorElectron.WindowManager.IsQuitOnWindowAllClosed=false;// Keep app running when windows close// Handle window lifecycleElectron.App.WindowAllClosed+=()=>{Console.WriteLine("All windows closed");if(Electron.WindowManager.IsQuitOnWindowAllClosed){Electron.App.Quit();}};// Create browser viewvarbrowserView=awaitElectron.WindowManager.CreateBrowserViewAsync(newBrowserViewConstructorOptions{WebPreferences=newWebPreferences{NodeIntegration=false,ContextIsolation=true}});// Add to windowawaitmainWindow.SetBrowserViewAsync(browserView);awaitbrowserView.WebContents.LoadURLAsync("https://example.com");// Set view boundsawaitmainWindow.SetBoundsAsync(browserView,newRectangle{X=0,Y=100,Width=800,Height=400});// Comprehensive window optionsvaroptions=newBrowserWindowOptions{Width=1200,Height=800,MinWidth=600,MinHeight=400,MaxWidth=1920,MaxHeight=1080,X=100,Y=100,Center=true,Frame=true,Title="My Application",Icon="assets/app-icon.png",Show=false,AlwaysOnTop=false,SkipTaskbar=false,Kiosk=false,TitleBarStyle=TitleBarStyle.Default,BackgroundColor="#FFFFFF",DarkTheme=false,Transparent=false,WebPreferences=newWebPreferences{NodeIntegration=false,ContextIsolation=true,EnableWebSQL=false,Partition="persist:electron",ZoomFactor=1.0f,DevTools=true}};// Create main windowvarmainWindow=awaitElectron.WindowManager.CreateWindowAsync(newBrowserWindowOptions{Width=1200,Height=800,Show=false});// Create secondary windowvarsecondaryWindow=awaitElectron.WindowManager.CreateWindowAsync(newBrowserWindowOptions{Width=600,Height=400,Parent=mainWindow,Modal=true,Show=false});// Load different contentawaitmainWindow.WebContents.LoadURLAsync("https://localhost:5001");awaitsecondaryWindow.WebContents.LoadURLAsync("https://localhost:5001/settings");// Show windows when readymainWindow.OnReadyToShow+=()=>mainWindow.Show();secondaryWindow.OnReadyToShow+=()=>secondaryWindow.Show();- Electron.App - Application lifecycle and window events
- Electron.Dialog - Parent windows for modal dialogs
- Electron.Menu - Window-specific menus
- Electron.WebContents - Window content management
- Electron Window Management Documentation - Official Electron window API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.