1

Windows 11 VS2022 WinUI3 Desktop WindowsAppSDK 1.2.230 .Net core 7

I'm creating a desktop app using MVPVM design principles. The documentation says that Microsoft.UI.Xaml.Window used within a UWP is not longer available, and is switching to Microsoft.UI.Windowsing.AppWindow.

I'm trying to add some page navigation and page content to the AppWindow. The AccountLinkView never displays. This is within the App.xaml.cs (which works fine) but I feel like I'm missing something.

protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        new MainWindow().Activate();
        if (e != null)
        {
            AppWindow rootWindow = WindowPresenter.Window;
            if (rootWindow == null)
            {
                WindowPresenter.Initialize();
                WindowPresenter.Navigate(typeof(AccountLinkView));
            }
            WindowPresenter.Show();
        }
    }

1 Answers1

1

You can refer to this Contributor's answer in Github https://github.com/microsoft/microsoft-ui-xaml/issues/6755

In Windows AppSDK, the AppWindow class doesn't own and manage its own window, but represents an existing window that already has content that was drawn using a UI framework.

So, you can not use AppWindow to navigate pages or windows.

You can set the page navigation and page content in the MainWindow with Frame.

 protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{
    m_window = new MainWindow();

    Frame rootFrame = new Frame();
    rootFrame.Navigate(typeof(AccountLinkView));

    m_window.Content = rootFrame;
    m_window.Activate();
}
Junjie Zhu - MSFT
  • 2,086
  • 1
  • 2
  • 6