3

I didn't found any documentation about this in C++. I used to use

winrt::Windows::ApplicationModel::Core::CoreApplication::CreateNewView(); to create a new view in UWP.

But now, I don't know how to do:

co_await wil::resume_foreground(*viewResource->Dispatcher.get());

// Here is still previous thread
DebugHelper::OutputCurrentThreadInfo();

winrt::Microsoft::UI::Xaml::Window testWindow = 
winrt::Microsoft::UI::Xaml::Window();
co_await wil::resume_foreground(testWindow.DispatcherQueue());
auto rootFrame = Microsoft::UI::Xaml::Controls::Frame();
rootFrame.Navigate(winrt::xaml_typename<EditPage>());
testWindow.Content(rootFrame);
testWindow.Activate();
co_await winrt::resume_background();

co_await winrt::resume_background();

Please help me. thanks

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Yonghui
  • 222
  • 3
  • 16
  • User interfaces are typically single-threaded. If you need to work with UI components you need to do it in the UI thread. – Some programmer dude Mar 31 '22 at 06:15
  • @Someprogrammerdude But in UWP, ApplicationModel::Core::CoreApplication::CreateNewView() will create a new thread for new window, so that even if the main window is destructed or crashed, the newly created window will still working... – Yonghui Apr 01 '22 at 06:30
  • There's a new AppWindow class (from Windows App SDK https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/windowing/windowing-overview) that you should be able to use. See here also: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/windowing you can create a Windows using `Microsoft::UI::Windowing::AppWindow::Create().Show(true)` and you don't need another thread. – Simon Mourier Apr 02 '22 at 06:29
  • @SimonMourier then how do I set content to AppWindow? I only found ElementCompositionPreview::SetAppWindowContent, but this method only provided in Windows.UI.Xaml.Hosting but not Microsoft.UI.Xaml.Hosting – Yonghui Apr 06 '22 at 07:51

0 Answers0