简体   繁体   中英

How can I create multiple windows in winui 3.0?

I would like to have a button that creates another window. I'm building off the template app you get in VS2019 Preview So far, I've created a new control BlankWindow, just the default one. I can see that in App::OnLaunched, a window is created with:

window = make<MainWindow>();
window.Activate();

So in my MainWindow.xaml.cs in my button click method, I put:

Window bWindow= make<BlankWindow>();
bWindow.Activate();

That doesn't build, I check the BlankWindow.idl file and see that BlankWindow inherits from Controls and not Windows, so I change it. Now it builds, but when I click the button in the MainWindow, I see the window flicker open and instantly close. What's going on?

Work on multi-window applications is ongoing. It's available as a Preview feature.

https://docs.microsoft.com/en-us/windows/apps/winui/winui3/#preview-features

You can find the solution to this problem in the definition of the Window Class for the Windows UI Library (WinUI) under the subtitle "Create a new Window on a new thread". To put the section in context it would help to read the entire webpage. It's not that long.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM