Window loses position after reopening. #328

Closed
opened 2026-01-29 16:36:33 +00:00 by claunia · 1 comment
Owner

Originally created by @Tum4ik on GitHub (May 29, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version:
    ElectronNET.CLI Version: 5.22.12.0
    ElectronNET.API Version: 5.22.12
    .NET Core Version: 2.2.300
    Node.js Version: 8.11.3

  • Target:
    Windows

I have a tray application. When I open window from tray context menu first time -> the window position is "center" (this is expected). But if I close the window and open again -> the window position becomes "top-left" (seems bug).

Steps to Reproduce:

  1. Create a simple desktopizer
/// <summary>
/// Provides functionality to bring the ASP.NET Core application to desktop.
/// </summary>
public class Desktoper
{
  private readonly MenuItem[] _menuItems;
  private BrowserWindow _testWindow;

  public Desktoper()
  {
    var testWindowOptions = new BrowserWindowOptions
    {
      MinWidth = 800,
      MinHeight = 400,
      Width = 800,
      Height = 400,
      Frame = false,
      Icon = _trayMenuSettingIcon,
      Fullscreenable = false
    };

    _menuItems = new[]
    {
        Label = "Test",
        Icon = _testMenuSettingIcon,
        Click = async () => _testWindow = await Electron.WindowManager.CreateWindowAsync(testWindowOptions)
      },
      new MenuItem
      {
        Type = MenuType.separator
      },
      new MenuItem
      {
        Label = _localizer["Exit"],
        Icon = _trayMenuExitIcon,
        Click = () => Electron.App.Quit()
      }
    };
  }


  /// <summary>
  /// Brings the ASP.NET Core application to desktop.
  /// </summary>
  public void Desktopize()
  {
    Electron.WindowManager.IsQuitOnWindowAllClosed = false;
    Electron.Tray.Show("path/to/tray-icon.png", _menuItems);
  }


  public void CloseSettingsWindow()
  {
    _testWindow?.Close();
  }
}

  1. Desktopize method should be called from Startup class Configure method. CloseSettingsWindow method is use when I press the Cancel button (see gif below).
  2. Run app and open the test window via tray context menu -> window will be positioned on the center of the screen.
  3. Close the test window and repeat the step 3 -> window will be positioned on top-left of the screen.

20190529_225402

Originally created by @Tum4ik on GitHub (May 29, 2019). Originally assigned to: @GregorBiswanger on GitHub. * **Version**: ElectronNET.CLI Version: 5.22.12.0 ElectronNET.API Version: 5.22.12 .NET Core Version: 2.2.300 Node.js Version: 8.11.3 * **Target**: Windows I have a tray application. When I open window from tray context menu first time -> the window position is "center" (this is expected). But if I close the window and open again -> the window position becomes "top-left" (seems bug). Steps to Reproduce: 1. Create a simple desktopizer ```csharp /// <summary> /// Provides functionality to bring the ASP.NET Core application to desktop. /// </summary> public class Desktoper { private readonly MenuItem[] _menuItems; private BrowserWindow _testWindow; public Desktoper() { var testWindowOptions = new BrowserWindowOptions { MinWidth = 800, MinHeight = 400, Width = 800, Height = 400, Frame = false, Icon = _trayMenuSettingIcon, Fullscreenable = false }; _menuItems = new[] { Label = "Test", Icon = _testMenuSettingIcon, Click = async () => _testWindow = await Electron.WindowManager.CreateWindowAsync(testWindowOptions) }, new MenuItem { Type = MenuType.separator }, new MenuItem { Label = _localizer["Exit"], Icon = _trayMenuExitIcon, Click = () => Electron.App.Quit() } }; } /// <summary> /// Brings the ASP.NET Core application to desktop. /// </summary> public void Desktopize() { Electron.WindowManager.IsQuitOnWindowAllClosed = false; Electron.Tray.Show("path/to/tray-icon.png", _menuItems); } public void CloseSettingsWindow() { _testWindow?.Close(); } } ``` 2. Desktopize method should be called from Startup class Configure method. CloseSettingsWindow method is use when I press the Cancel button (see gif below). 3. Run app and open the test window via tray context menu -> window will be positioned on the center of the screen. 4. Close the test window and repeat the step 3 -> window will be positioned on top-left of the screen. ![20190529_225402](https://user-images.githubusercontent.com/21317790/58587050-1957c100-8265-11e9-9337-76c56deee80b.gif)
claunia added the bug label 2026-01-29 16:36:33 +00:00
Author
Owner

@Tum4ik commented on GitHub (May 29, 2019):

Actually it could be fix by

new MenuItem
{
  Label = _localizer["Settings"],
  Icon = _trayMenuSettingIcon,
  Click = async () =>
  {
    _settingsWindow = await Electron.WindowManager.CreateWindowAsync(_settingsWindowOptions);
    _settingsWindow.Center(); // <---- Fix
  }
},

But I don't know. It seems it is not obvious.

@Tum4ik commented on GitHub (May 29, 2019): Actually it could be fix by ```csharp new MenuItem { Label = _localizer["Settings"], Icon = _trayMenuSettingIcon, Click = async () => { _settingsWindow = await Electron.WindowManager.CreateWindowAsync(_settingsWindowOptions); _settingsWindow.Center(); // <---- Fix } }, ``` But I don't know. It seems it is not obvious.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#328