强制 WinRT 应用程序捕捉视图视图、应用程序、WinRT

2023-09-06 06:12:28 作者:岁月蹉跎

对于我的一个应用,我想在点击按钮后将该应用发送到快照视图.据我所知,没有可用于将正在运行的应用程序发送到快照视图的公共 API.有人找到解决方法吗?

For one of my apps I'd like to send the app to snapped view after tapping a button. As far as I know there's no public API available to send a running application to snapped view. Did anyone find a workaround to do this?

这应该是可能的,因为您可以在 Windows 8 本身中执行此操作,并捕捉其中一个正在运行的应用程序.

Somehow it should be possible since you're able to do it in Windows 8 itself, and snap one of the running apps.

更新:能够触发 Win+.可能会做同样的伎俩,但 SendKeys API 在 WinRT 中也不可用.

Update: Being able to trigger a Win+. might do the same trick, but the SendKeys API isn't available in WinRT either.

推荐答案

Windows 10 有一个 ApplicationView.TryResizeView 方法

Windows 10 has a ApplicationView.TryResizeView method

所以...总结一下有趣的 WinRT 之旅:

So... to summarize the interesting WinRT journey:

具有快照"模式,只有用户才能启动.开发者可以尝试使用 TryUnsnap 方法取消捕捉

Has a a 'Snapped' mode that a only a user can initiate. the developer can try to unsnap with the TryUnsnap method

没有 Snapped 模式,不推荐使用 TryUnsnap.开发者仍然可以监听窗口大小的变化,并知道应用视图是否像以前一样小.

Does not have Snapped mode, and TryUnsnap is deprecated. The dev can still listen for window size changes and know if the app view is in a smaller size as before.

引入了 ApplicationView.TryResizeView 方法,开发人员可以尝试 调整大小.窗口大小更改事件仍然存在.

Introduced the ApplicationView.TryResizeView method, where the dev can try to resize. Window size changed event is still there.

ApplicationView.GetForCurrentView().TryResizeView(new size(width, height)));