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.
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, usingDispatcher.RunAsync
, on that view's UI thread. You should use that thread of the open window to callTryShowAsStandaloneAsync
to launch your new main view. You can then callWindow.Activate
using the new main view's dispatcher.I'm not sure if you're using
Dispatcher.RunAsync
to create the view, i.e:for more info, please refer to : https://daxsnippets.wordpress.com/2015/07/09/windows-10-create-views/
Answering why
TryShowAsStandaloneAsync
fails once you have closed the main window:I think
TryShowAsStandaloneAsync
tries to use the main view as the anchor view (ie, a window to place the new window relative to).Once you close the main window
TryShowAsStandaloneAsync
fails because it has no anchor view.The workaround is to specify an
anchorViewId
of a view that is open (one of the new windows you opened prior to closing the main window), via an overload of TryShowAsStandaloneAsync:From this answer.