Skip to content

feat: Multi Window Support#72

Open
0xApp wants to merge 1 commit intoDotNetExtension:mainfrom
0xApp:main
Open

feat: Multi Window Support#72
0xApp wants to merge 1 commit intoDotNetExtension:mainfrom
0xApp:main

Conversation

@0xApp
Copy link

@0xApp 0xApp commented Feb 26, 2026

Multi Window Support

Summary

  • Add IWindowManager service for opening and managing multiple desktop windows, each with an independent Blazor component tree
  • Add Razor component for declarative window management (open on render, close on dispose)
  • Refactor BlazorDesktopWindow to accept WindowOptions POCO instead of reading IConfiguration directly, enabling child windows with custom settings
  • Add multi-window demo page to BlazorDesktop.Sample showcasing both service-based and component-based APIs
  • Update README with multi-window documentation, API reference, and updated examples

New files

  • Hosting/WindowOptions.cs - Per-window configuration POCO with FromConfiguration() factory
  • Hosting/DesktopWindowHandle.cs - Lightweight handle to a managed window (Id, IsMainWindow, Closed event)
  • Services/IWindowManager.cs - Public interface: OpenAsync(), CloseAsync(), MainWindow, events
  • Services/WindowManager.cs - Internal implementation with ConcurrentDictionary tracking, WPF Dispatcher marshaling
  • Components/DesktopWindow.cs - Blazor component wrapping IWindowManager for declarative usage

Modified files

  • Wpf/BlazorDesktopWindow.cs - Added internal constructor accepting WindowOptions + RootComponentMappingCollection; replaced all IConfiguration reads with _options field
  • Hosting/BlazorDesktopHostBuilder.cs - Replaced BlazorDesktopWindow singleton with IWindowManager/WindowManager singleton
  • Services/BlazorDesktopService.cs - Creates BlazorDesktopWindow manually on STA thread; registers with WindowManager

Breaking change

BlazorDesktopWindow is no longer registered in the DI container. Code that injected it directly must use IWindowManager.MainWindow.NativeWindow instead.

Test plan

  • dotnet build BlazorDesktop.sln succeeds with 0 warnings/errors
  • Run BlazorDesktop.Sample, verify main window works identically to before
  • Navigate to Multi-Window page, click "Open Window (Service)" - child window opens with correct title/size and independent counter
  • Click "Open Window (Component)" - toggle opens/closes a declarative child window
  • Close a child window via X button - Closed event fires, window count updates, main app stays open
  • Close main window - all child windows close and app exits

@0xApp 0xApp mentioned this pull request Feb 26, 2026
1 task
@0xApp 0xApp changed the title Multi Window Support feat: Multi Window Support Feb 26, 2026
@russkyc
Copy link

russkyc commented Feb 28, 2026

This is how i would imagine #42 would be api-wise, @andrewbabbittdev what do you think?

@andrewbabbittdev
Copy link
Collaborator

andrewbabbittdev commented Feb 28, 2026

Mmmm generally prefer to start with a design proposal before starting on a PR @russkyc I would still like to see one filled out to go with this PR. It is under the issue templates.

I just got back from vacation so I wont have time to go over this for a little as I catch up on work and other stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants