Setting Modal = true in BrowserOptions does not work #767

Closed
opened 2026-01-29 16:48:02 +00:00 by claunia · 13 comments
Owner

Originally created by @lukebordonaro on GitHub (Feb 21, 2022).

  • Version: 13.5.1

  • Target: windows

If you set BrowserWindowOptions.Modal = true when creating a new BrowserWindow, the created window will not be a modal window even after setting the parent.

Consider this code:

var parent = Electron.WindowManager.BrowserWindows.First(); // assume a main window exists and this returns it
var child = await Electron.WindowManager.CreateWindowAsync(
            new BrowserWindowOptions
            {
                Show = false,
                Modal = true
            });
child.SetParentWindow(parent);

child.OnReadyToShow += () =>
{
    child.Show();
}

child.OnShow += async () =>
{
    var isModal = await child.IsModalAsync();
}

The observed behavior of the child window is that it is NOT a modal window, and you can still interact with the main window (parent). The value of isModal in the OnShow handler is false, too.

I haven't investigated this, but it's possible that for modal windows to work the parent must be set inside the BrowserWindowOptions: https://www.electronjs.org/docs/latest/api/browser-window/#modal-windows

Originally created by @lukebordonaro on GitHub (Feb 21, 2022). * **Version**: 13.5.1 * **Target**: windows If you set `BrowserWindowOptions.Modal = true` when creating a new `BrowserWindow`, the created window will not be a modal window even after setting the parent. Consider this code: ```cs var parent = Electron.WindowManager.BrowserWindows.First(); // assume a main window exists and this returns it var child = await Electron.WindowManager.CreateWindowAsync( new BrowserWindowOptions { Show = false, Modal = true }); child.SetParentWindow(parent); child.OnReadyToShow += () => { child.Show(); } child.OnShow += async () => { var isModal = await child.IsModalAsync(); } ``` The observed behavior of the child window is that it is NOT a modal window, and you can still interact with the main window (`parent`). The value of `isModal` in the `OnShow` handler is `false`, too. I haven't investigated this, but it's possible that for modal windows to work the `parent` must be set inside the `BrowserWindowOptions`: https://www.electronjs.org/docs/latest/api/browser-window/#modal-windows
claunia added the bug label 2026-01-29 16:48:02 +00:00
Author
Owner

@lukebordonaro commented on GitHub (Feb 21, 2022):

Update: I tested some changes locally and can confirm that setting a parent in the BrowserWindowOptions fixes the issue. Would you like me to make a PR with my test changes?

@lukebordonaro commented on GitHub (Feb 21, 2022): Update: I tested some changes locally and can confirm that setting a `parent` in the `BrowserWindowOptions` fixes the issue. Would you like me to make a PR with my test changes?
Author
Owner

@danatcofo commented on GitHub (Feb 21, 2022):

Interesting... id be interested to see if the javascript version of the add parent works or not. If it does work, sounds like a bug in the implementation of that function.

@danatcofo commented on GitHub (Feb 21, 2022): Interesting... id be interested to see if the javascript version of the add parent works or not. If it does work, sounds like a bug in the implementation of that function.
Author
Owner

@lukebordonaro commented on GitHub (Feb 21, 2022):

The call to SetParentWindow does work as expected, for the most part. Calling this in C# does change the grouping of the windows on my taskbar.

I'm thinking this is a side-effect of native APIs. Window types may need to be set when the window is created, which is probably why the Electron docs state "to create a modal window, you have to set both parent and modal options" (emphasis mine).

@lukebordonaro commented on GitHub (Feb 21, 2022): The call to `SetParentWindow` does work as expected, for the most part. Calling this in C# does change the grouping of the windows on my taskbar. I'm thinking this is a side-effect of native APIs. Window types may need to be set when the window is created, which is probably why the Electron docs state "to create a modal window, you have to set **both** parent and modal **options**" (emphasis mine).
Author
Owner

@danatcofo commented on GitHub (Feb 21, 2022):

Well if thats the case then this is less a bug and more of a documentation issue. You might add to the readme.

I think more and more we need a howto or faq or something about some of these common issues.

@danatcofo commented on GitHub (Feb 21, 2022): Well if thats the case then this is less a bug and more of a documentation issue. You might add to the readme. I think more and more we need a howto or faq or something about some of these common issues.
Author
Owner

@lukebordonaro commented on GitHub (Feb 21, 2022):

@danatcofo unfortunately it's not just a documentation issue. To create a modal window, ElectronNET needs to add the Parent property to BrowserWindowOptions. It's currently impossible to create a modal window in C#.

@lukebordonaro commented on GitHub (Feb 21, 2022): @danatcofo unfortunately it's not just a documentation issue. To create a modal window, ElectronNET needs to add the `Parent` property to `BrowserWindowOptions`. It's currently impossible to create a modal window in C#.
Author
Owner

@monisha-soliton commented on GitHub (Mar 18, 2022):

Hi @MutatedGamer

We are facing the same issue. We would like to try out the fix you have made locally. Is it possible for you to share the updated code for us to try out? If sharing the code is not possible by any chance please let us know the list of changes to try out the fix.

Also, please let us know if there is any plan to release the fix anytime soon

@monisha-soliton commented on GitHub (Mar 18, 2022): Hi @MutatedGamer We are facing the same issue. We would like to try out the fix you have made locally. Is it possible for you to share the updated code for us to try out? If sharing the code is not possible by any chance please let us know the list of changes to try out the fix. Also, please let us know if there is any plan to release the fix anytime soon
Author
Owner

@lukebordonaro commented on GitHub (Mar 18, 2022):

@MonishaMaryA I'll submit a pull request this weekend with the changes I made to get it working

@lukebordonaro commented on GitHub (Mar 18, 2022): @MonishaMaryA I'll submit a pull request this weekend with the changes I made to get it working
Author
Owner

@monisha-soliton commented on GitHub (Mar 22, 2022):

@MutatedGamer

Thanks for the update. Let us know once you submit a pull request. Do you have any idea on when the pull request will be merged and released?

@monisha-soliton commented on GitHub (Mar 22, 2022): @MutatedGamer Thanks for the update. Let us know once you submit a pull request. Do you have any idea on when the pull request will be merged and released?
Author
Owner

@lukebordonaro commented on GitHub (Mar 22, 2022):

@MonishaMaryA I created PR https://github.com/ElectronNET/Electron.NET/pull/673

I cannot speak for when it would likely get merged or released. I've been working off a local build of the library that I push to a local filesystem nuget feed.

@lukebordonaro commented on GitHub (Mar 22, 2022): @MonishaMaryA I created PR https://github.com/ElectronNET/Electron.NET/pull/673 I cannot speak for when it would likely get merged or released. I've been working off a local build of the library that I push to a local filesystem nuget feed.
Author
Owner

@monisha-soliton commented on GitHub (Mar 22, 2022):

Sure @MutatedGamer

Thank you so much for updating the fix and sharing the PR. We will also try to build locally and work.

@monisha-soliton commented on GitHub (Mar 22, 2022): Sure @MutatedGamer Thank you so much for updating the fix and sharing the PR. We will also try to build locally and work.
Author
Owner

@monisha-soliton commented on GitHub (Mar 24, 2022):

@robertmuehsig , @GregorBiswanger

Could you please let us know when the pull request #673 will be merged and released?

@monisha-soliton commented on GitHub (Mar 24, 2022): @robertmuehsig , @GregorBiswanger Could you please let us know when the pull request #673 will be merged and released?
Author
Owner

@monisha-soliton commented on GitHub (May 4, 2023):

Hi @GregorBiswanger ,

In the latest release 23.6.1, this fix is not reflected. Could you please check on this issue again?

@monisha-soliton commented on GitHub (May 4, 2023): Hi @GregorBiswanger , In the latest release 23.6.1, this fix is not reflected. Could you please check on this issue again?
Author
Owner

@monisha-soliton commented on GitHub (May 9, 2023):

Hi @GregorBiswanger and @FlorianRappl

I see that the PR 673 was merged to master branch which is now stale. We need this to be fixed as soon as possible. Could you please let us know if there is any possibility for fixing this and release the update any time sooner

@monisha-soliton commented on GitHub (May 9, 2023): Hi @GregorBiswanger and @FlorianRappl I see that the PR [673](https://github.com/ElectronNET/Electron.NET/pull/673) was merged to master branch which is now stale. We need this to be fixed as soon as possible. Could you please let us know if there is any possibility for fixing this and release the update any time sooner
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#767