How to make Window.Current visible after it was closed?

吃可爱长大的小学妹 提交于 2019-12-10 19:01:51

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/33690029/how-to-make-window-current-visible-after-it-was-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!