我正在使用 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[] {});
}
基于BrowserWindow
源和 Electron.NET 演示,下面的演示在最大化窗口中打开电子窗口。
这只是在显示窗口后手动调用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[] {});
}
希望这有帮助。