-
Hello! I've been excited to try out MAUI for a while and start today poking around with it. Most of the things work great out of the box also together with Blazor. Though I have some concerns and things I don't quite understand how to achieve. For example, if I want to set a size for the current window in a nice way, let's say on Windows desktop but also on Mac (I've found a event listening solution, too hacky for my taste), what would the best practices to do that if I want to do it from the platform folders? As I understand, the code that creates the application windows is initiated after. Secondly, how can I create a NotifyIcon with MAUI? I want to be able to do that on Windows but also MacOS, I'm not really sure how to approach that problem at all tbh. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
To help any other lost souls out there, I created a work around I'm more happy with than the default boilerplate: In MauiProgram.cs public static class MauiProgram
{
public static MauiAppBuilder CreateMauiApp()
{
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
builder.Services.AddMauiBlazorWebView();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
#endif
builder.Services.AddSingleton<WeatherForecastService>();
return builder;
}
} This is the default boilerplate except that you return the builder instead of builder.Build(). The reason for this is because then in your App.xaml in your Windows folder: protected override MauiApp CreateMauiApp() {
MauiAppBuilder builder = MauiProgram.CreateMauiApp();
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(windows =>
{
windows.OnWindowCreated(window =>
{
System.Diagnostics.Debug.WriteLine(window.Title);
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId nativeWindowId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow appWindow = AppWindow.GetFromWindowId(nativeWindowId);
SizeInt32 sizeStruct = new();
sizeStruct.Width = 1280;
sizeStruct.Height = 720;
appWindow.Resize(sizeStruct);
});
});
});
return builder.Build();
} You don't have to write ugly preprocessor directives and keep platform specific code to where they should be. Maybe this will be addressed close to the release! |
Beta Was this translation helpful? Give feedback.
To help any other lost souls out there, I created a work around I'm more happy with than the default boilerplate:
In MauiProgram.cs
This is the default boilerplate except that you return the builder instead of builder.Build(). The…