1

我正在使用 electron.Net,但是当我启动主窗口时,它总是打开与中心对齐的小尺寸。

这是我的代码:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
        app.UseDeveloperExceptionPage();
    } else {
        app.UseExceptionHandler("/Home/Error");
    }
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    });

    Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());

    Electron.Menu.SetApplicationMenu(new MenuItem[] {});
}
4

1 回答 1

1

基于BrowserWindow 源代码Electron.NET Demo,以下是在最大化窗口中打开 Electron 窗口。

这只是在显示窗口后手动调用BrowserWindow'Maximize()事件,当一切准备就绪时。

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
        app.UseDeveloperExceptionPage();
    } else {
        app.UseExceptionHandler("/Home/Error");
    }
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    });
    
    if (HybridSupport.IsElectronActive)
    {
        ElectronBootstrap();
    }
}

public async void ElectronBootstrap()
{
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
    {
        Width = 1152,
        Height = 940,
        Show = false
    });

    await browserWindow.WebContents.Session.ClearCacheAsync();

    // For the gracefull showing of the Electron Window when ready
    browserWindow.OnReadyToShow += () =>
    {
        browserWindow.Show();
        browserWindow.Maximize();
    }
    Electron.Menu.SetApplicationMenu(new MenuItem[] {});
} 

希望这可以帮助。

于 2020-07-04T09:51:32.927 回答