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

后端 未结 3 1002
执念已碎
执念已碎 2021-02-04 10:50

I do know how to open additional windows using TryShowAsStandaloneAsync. However, if the original window is closed - TryShowAsStandaloneAsync fails (Wh

3条回答
  •  忘了有多久
    2021-02-04 11:28

    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:

    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.

提交回复
热议问题