-
I recently upgraded my MAUI 8 app to MAUI 9. One of the things I had to change was that I had to replace the So I overrode that function with the logical implementation: protected override Window CreateWindow(IActivationState? activationState)
{
ArgumentNullException.ThrowIfNull(activationState);
var window = base.CreateWindow(activationState);
window.Page = activationState.Context.Services.GetRequiredService<AppShell>();
return window;
} However, to facilitate this, I must also register an implementation of public class WindowCreator : IWindowCreator
{
public Window CreateWindow(Application app, IActivationState? activationState) => new();
} This works perfectly, but it leaves me with questions.
The current state of the code seems incomplete, and ready for further development. I saw StackOverflow answers that override |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I can see that https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/windows?view=net-maui-9.0#decouple-window-management-from-the-app-class mentions that one must register the creator: builder.Services.AddSingleton<IWindowCreator, WindowCreator>(); Perhaps you can file an issue here https://github.com/dotnet/docs-maui/issues to ask for more details or create a PR to add information that is not obvious. |
Beta Was this translation helpful? Give feedback.
-
I'm currently using this approach where I register the class below as a singleton
public class WindowCreator : IWindowCreator
{
public Window CreateWindow(Application app, IActivationState? activationState)
{
var window = new Window();
if (!app.Windows.Any())
{
// First window created shows the main page.
// Note: Your main page class will most likely be different.
window.Page = activationState?.Context.Services.GetRequiredService<AppShell>();
}
return window;
}
} If using this approach, do not set |
Beta Was this translation helpful? Give feedback.
I'm currently using this approach where I register the class below as a singleton
IWindowCreator
.I improved upon some problems I recognised in the documented approach:
Think of apps like Spotify and Discord that close their main window, but keep running, and leave some method to create a new main window again, that shows the page as it were when you closed it.