在Win UI 3中,如何更改主窗口页面?
在Win UI 3中,当用户单击按钮时,我想更改MainWindow的内容。现在,我拥有所有内容的MainWindow,然后用户单击一个按钮,然后打开一个新窗口,我们将其称为SecondWindow。我这样做是:
Window secondWindow= new SecondWindow();
secondWindow.Activate();
但是我想要的是要在主窗口中打开Secondwindow的内容,代替MainWindow的内容。我该怎么做?
In Win UI 3 I want to change the content of the MainWindow when the user clicks a button. Right now I have the MainWindow with all its content, then the user clicks a button and a new window opens, let's call it SecondWindow. I do this with:
Window secondWindow= new SecondWindow();
secondWindow.Activate();
But what I want is for SecondWindow's content to open in the main window, in place of MainWindow's content. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望在另一个窗口内显示
secondwindow
的内容,则应是usercontrol
而不是窗口。然后,您可以简单地作为主窗口的根面板的孩子添加一个实例:
mainwindow.xaml:
mainwindow.xaml.cs:,
如果您定义了内容直接在窗口中,您应该将其
content
添加到主窗口中:If you want the display the contents of the
secondWindow
inside another window, it should be aUserControl
instead of a window.You could then simply add an instance of it as a child of the root panel of the main window:
MainWindow.xaml:
MainWindow.xaml.cs:
If you define the contents directly in a window, you should add its
Content
to the main window like this: