首先放入一个button,设置点击事件。
1、显示新视图:
CoreApplicationView newView = CoreApplication.CreateNewView();
显示新视图
2、跟踪新视图的 Id。 稍后使用此选项来显示视图。
int newViewId = 0;
3、
在新线程上,填充窗口。
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(SecondaryPage), null);
Window.Current.Content = frame;
// You have to activate the window in order to show it later.
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
4、通过调用 ApplicationViewSwitcher.TryShowAsStandaloneAsync 显示新视图。
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
总体代码:
private async void Button_Click(object sender, RoutedEventArgs e)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Frame frame = new Frame();
frame.Navigate(typeof(SecondaryPage), null);
Window.Current.Content = frame;
// You have to activate the window in order to show it later.
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
参考:https://docs.microsoft.com/zh-cn/windows/uwp/layout/show-multiple-views