I have an application that opens new windows. If the original window is closed and then the user starts the app (e.g. from the start menu) - TryShowAsStandaloneAsync
fails in opening a new window (Why?). So I want to "revive" the original one. But though I use Window.Current.Activate();
and frame.Navigate(...);
- Window.Current.Visible
is always false
(and the window is not shown again).
So how can I "revive" a closed window? (Or use TryShowAsStandaloneAsync
from a closed 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:
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
viewIdToShow, // Id of a new view, or of your hidden main view
ViewSizePreference.Default,
anchorViewId, // Id of one of your visible windows
ViewSizePreference.Default);
From this answer.