Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a universal windows app have multiple independent windows (Like Microsoft's app “Photos”)?

I do know how to open additional windows using TryShowAsStandaloneAsync. However, if the original window is closed - TryShowAsStandaloneAsync fails (Why?). And I don't know how to "revive" it (-the original window).

But "Photos" seems to work fine just like a desktop application. How does it do that? (I'd like to emulate that.) One can open a window with an image, open another one, close the first, and still be able to open more windows.

Any way would be fine - some way to launch windows without the main window showing, or some way of reviving the main window after it's closed (in order for it to be the new window that has to be opened), or some other way.

like image 723
ispiro Avatar asked Nov 13 '15 12:11

ispiro


1 Answers

Have a look at the MultipleViews sample app. This app does have the problem you're describing.

Each view that you create will have their own UI Thread, and therefore dispatcher. The key to this app is that TryShowAsStandaloneAsync is called from the dispatcher of the currently active window.

In the sample's OnLaunched event, the code looks for a reference to the currently open view, using the view id from the launch arguments. It then uses the dispatcher associated with that view to call UI code, using Dispatcher.RunAsync, on that view's UI thread. You should use that thread of the open window to call TryShowAsStandaloneAsync to launch your new main view. You can then call Window.Activate using the new main view's dispatcher.

like image 173
Hannes Nel Avatar answered Oct 13 '22 00:10

Hannes Nel