UWP新建窗口

首先放入一个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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章