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

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