英文:
WindowsApp AppWindow content
问题
Windows 11
VS2022
WinUI3 Desktop WindowsAppSDK 1.2.230
.Net core 7
我正在使用MVPVM设计原则创建桌面应用程序。文档表示,UWP中使用的Microsoft.UI.Xaml.Window已不再可用,现在切换到Microsoft.UI.Windowsing.AppWindow。
我试图在AppWindow中添加一些页面导航和页面内容。AccountLinkView从未显示过。
这是在App.xaml.cs中(它运行正常),但我感觉我漏掉了一些东西。
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();
}
}
英文:
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
得分: 1
你可以参考这位贡献者在 Github 上的答案:https://github.com/microsoft/microsoft-ui-xaml/issues/6755
在 Windows AppSDK 中,AppWindow
类不拥有和管理自己的窗口,而是表示已经使用 UI 框架绘制内容的现有窗口。
因此,你不能使用 AppWindow
导航页面或窗口。
你可以在主窗口中设置页面导航和页面内容 使用 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();
}
英文:
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();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论