DotNetExtension / BlazorDesktop

Create desktop apps using Blazor.
MIT License
53 stars 8 forks source link

implement the use of CenterScreen #55

Open PabloKench opened 5 days ago

PabloKench commented 5 days ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I started using blazor desktop, I noticed that it uses wpf, but I can't find a way to use WindowStartupLocation as CenterScreen

Describe the solution you'd like

Implementing this would be good, since most apps today are opened as centralized

Additional context

No response

AndrewBabbitt97 commented 4 days ago

Most apps should actually remember the last location an app was used / opened at which is the bigger problem as I don't believe that works currently. The current settings should be the windows default behavior, where Windows will open multiple windows from the top left corner, you can see this behavior in File Explorer.

As a workaround you should be able to get access to the BlazorDesktopWindow in Program.cs and set the property yourself:

using BlazorDesktop.Hosting;
using HelloWorld.Components;
using Microsoft.AspNetCore.Components.Web;

var builder = BlazorDesktopHostBuilder.CreateDefault(args);

builder.RootComponents.Add<Routes>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

if (builder.HostEnvironment.IsDevelopment())
{
    builder.UseDeveloperTools();
}

var app = builder.Build();

var window = app.Services.GetRequiredService<BlazorDesktopWindow>();

window.WindowStartupLocation = WindowStartupLocation.CenterScreen;

await app.RunAsync();
AndrewBabbitt97 commented 4 days ago

Realistically we need to evaluate better window options, this ties into #42

It would probably be better if we also exposed the main window as a property under the BlazorDesktopHostBuilder.