一个通用的windows应用程序怎么可以有多个独立的窗口(比如微软的应用程序“照片")? [英] How can a universal windows app have multiple independent windows (Like Microsoft's app “Photos”)?

查看:30
本文介绍了一个通用的windows应用程序怎么可以有多个独立的窗口(比如微软的应用程序“照片")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用 TryShowAsStandaloneAsync 打开其他窗口.但是,如果原始窗口关闭 - TryShowAsStandaloneAsync 失败(为什么?).而且我不知道如何恢复"它(-原始窗口).

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.

推荐答案

查看MultipleViews 示例应用.此应用确实存在您所描述的问题.

Have a look at the MultipleViews sample app. This app does have the problem you're describing.

您创建的每个视图都有自己的 UI 线程,因此也有调度程序.这个应用程序的关键是从当前活动窗口的调度程序调用 TryShowAsStandaloneAsync.

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.

在示例的 OnLaunched 事件中,代码使用启动参数中的视图 ID 查找对当前打开的视图的引用.然后,它使用与该视图关联的调度程序在该视图的 UI 线程上使用 Dispatcher.RunAsync 调用 UI 代码.您应该使用打开窗口的那个线程来调用 TryShowAsStandaloneAsync 来启动新的主视图.然后,您可以使用新的主视图的调度程序调用 Window.Activate.

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, using Dispatcher.RunAsync, on that view's UI thread. You should use that thread of the open window to call TryShowAsStandaloneAsync to launch your new main view. You can then call Window.Activate using the new main view's dispatcher.

这篇关于一个通用的windows应用程序怎么可以有多个独立的窗口(比如微软的应用程序“照片")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆