Force WinRT app to snapped view

2019-01-29 08:54发布

问题:

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?

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

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

回答1:

Windows 10 has a ApplicationView.TryResizeView method

So... to summarize the interesting WinRT journey:

Windows 8

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

Windows 8.1

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.

Windows 10

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


回答2:

There is no way to force an application into snapped mode - it has to be a user initiated action.

An application can request to be unsnapped through:

Windows.UI.ViewManagement.ApplicationView.TryUnsnap();

Which tries to push the app into fill mode.