关闭后如何使Window.Current可见? [英] How to make Window.Current visible after it was closed?
问题描述
我有一个打开新窗口的应用程序.如果关闭了原始窗口,然后用户启动了该应用程序(例如,从开始菜单中启动)- TryShowAsStandaloneAsync
无法打开新窗口(为什么?).因此,我想复兴"原始版本.但是尽管我使用了 Window.Current.Activate();
和 frame.Navigate(...);
- Window.Current.Visible
是始终为 false
(并且不会再次显示该窗口).
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).
那么我该如何重生"一个关闭的窗口?(或在关闭的窗口中使用 TryShowAsStandaloneAsync
.)
So how can I "revive" a closed window? (Or use TryShowAsStandaloneAsync
from a closed window.)
推荐答案
我认为 TryShowAsStandaloneAsync
尝试将主视图用作锚视图(即,一个相对于放置新窗口的窗口)
I think TryShowAsStandaloneAsync
tries to use the main view as the anchor view (ie, a window to place the new window relative to).
一旦关闭主窗口, TryShowAsStandaloneAsync
就会失败,因为它没有锚点视图.
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);
来自此答案.
这篇关于关闭后如何使Window.Current可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!