1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UWP 新しいウィンドウを表示する。

Posted at

新規Windowを作成し、表示する方法

2通りの方法がある。

方法1

新規作成されるウィンドウは、もとのウィンドウと同じスレッドで作成される。

window1.cs
var frame = new Frame();
//frame.Navigate(typeof(AnotherPage));

var appWindow = await AppWindow.TryCreateAsync();
ElementCompositionPreview.SetAppWindowContent(appWindow, frame);

await appWindow.TryShowAsync();

方法2

新規作成されるウィンドウは、もとのウィンドウと別のスレッドで作成される。

window2.cs
CoreApplicationView newView = CoreApplication.CreateNewView();

int id = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
    var frame = new Frame();
    //frame.Navigate(typeof(AnotherPage));

    Window.Current.Content = frame;
    Window.Current.Activate();
    id = ApplicationView.GetForCurrentView().Id;
});

await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id);

まとめ

方法1
https://docs.microsoft.com/ja-jp/windows/uwp/design/layout/app-window

方法2
https://docs.microsoft.com/ja-jp/windows/uwp/design/layout/application-view

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?