Skip to content

WindowManager

github-actions[bot] edited this page Oct 31, 2025 · 1 revision

Create and manage browser windows, control window behavior and appearance.

Overview

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.

Properties

📋 IReadOnlyCollection<BrowserView> BrowserViews

Gets a read-only collection of all currently open browser views.

📋 IReadOnlyCollection<BrowserWindow> BrowserWindows

Gets a read-only collection of all currently open browser windows.

📋 bool IsQuitOnWindowAllClosed

Controls whether the application quits when all windows are closed. Default is true.

Methods

🧊 Task<BrowserView> CreateBrowserViewAsync()

Creates a new browser view with default options.

Returns:

The created BrowserView instance.

🧊 Task<BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options)

Creates a new browser view with custom options.

Parameters:

  • options - Browser view configuration options

Returns:

The created BrowserView instance.

🧊 Task<BrowserWindow> CreateWindowAsync(string loadUrl = "http://localhost")

Creates a new browser window with default options.

Parameters:

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 options
  • loadUrl - URL to load in the window. Defaults to "http://localhost"

Returns:

The created BrowserWindow instance.

Usage Examples

Basic Window Creation

// 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");

Window Management

// 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();}};

Browser View Integration

// 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});

Window Options Configuration

// 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}};

Multi-Window Applications

// 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();

Related APIs

Additional Resources

Clone this wiki locally