new main window in net 9 changed

Dani_S 4,016 Reputation points
2025-01-27T07:43:15.64+00:00

Hi,

I looked in app.xaml.cs file in net 9 and create instance of main window change to:

protected`` override Window CreateWindow(IActivationState? activationState)

{

return`` new Window(new AppShell());

}

  1. is must?
  2. why this change?
  3. Is releavant for mac and windows ?

Thanks,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,871 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ki-lianK-7341 770 Reputation points
    2025-01-27T07:56:45.5166667+00:00

    Why the Change?

    In .NET 9, you use CreateWindow to set up the main window. This helps manage the app lifecycle better and supports multiple windows.

    Is It Necessary?

    Yes, it’s required in .NET 9. The old MainPage property is deprecated.

    Relevance for Mac and Windows

    This change applies to both macOS and Windows.

    Here’s the code:

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new Window(new AppShell());
    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.