windows-store-apps - FileSavePicker 和已弃用的 ApplicationViewState

标签 windows-store-apps

FileSavePicker 的文档中,它指出:

Warning If you try to show the file picker while your app is snapped the file picker will not be shown and an exception will be thrown. You can avoid this by making sure your app is not snapped or by unsnapping it before you call the file picker.

我目前正在检查应用程序是否已捕捉,并且我的应用程序在每种情况下的响应都不同。我的默认行为也不显示 FileSavePicker,所以我不能只是尝试然后退回到其他内容。我也不想强制应用程序取消锁定。

但是,ApplicationViewState 8.1 后已弃用。在该文档和相关搜索中,建议开发人员直接访问窗口大小以确定正确的行为。但是,如果 View 状态不再可用,我如何知道文件选择器是否会抛出异常?应用程序的尺寸多大才被视为“贴合”?

另外,我正在使用 C++,所以与 C++ 兼容的答案将是非常棒的。我也不介意查看 C# 解决方案。

最佳答案

关于 FileSavePicker 文档 - 我认为这只是一个疏忽。您引用的文本来自 Windows 8 版本,在我看来,它似乎没有针对 Windows 8.1 进行更新。

如果你看FileOpenPicker documentation ,您会看到它已更新:

Important In Windows 8 if you attempt to display the file picker while your app is snapped, the file picker will not be shown and an exception will be thrown. You can avoid this by making sure your app is not snapped, or by unsnapping it before you call the file picker. ...Note that Windows 8.1 does not define a specific snapped window size. Instead, users can resize apps to any width, down to the minimum. Therefore, if your app will deploy only on Windows 8.1, you can ignore the EnsureUnsnapped function and calls to it in this topic's example code.

上面最后一句(粗体)本质上是说,如果您在 Windows 8.1 下运行,则可以忽略状态并安全地打开文件对话框。


为了测试上述内容,我使用 VS 2012 创建了一个带有文件保存选择器的 Windows 8 应用程序(用 C# 编写)。我相信结果与 C++ 相同,但我不能 100% 确定。

我应该注意,我的测试应用程序不会检查 View 状态,并且总是尝试打开文件对话框。

当应用程序在 Windows 8 下以快照状态运行时,应用程序会导致错误。在 Windows 8.1 下运行相同的应用程序(相同的二进制文件)时,可以毫无问题地打开文件保存对话框。如前所述,Windows 8.1 中没有捕捉状态,因此我测试应用程序的方式是将应用程序打开到最小宽度(320 像素)。


总结一下:

  • 如果您的目标平台是 Windows 8.0,则必须确保在打开文件选择器对话框之前取消应用程序的捕捉。
  • 如果您的目标平台是 Windows 8.1,则不必担心状态,因为文件选择器对话框不再抛出任何异常。

关于windows-store-apps - FileSavePicker 和已弃用的 ApplicationViewState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25516313/

相关文章:

windows-store-apps - UWP appx 包 Signtool "Error: SignerSign() failed."(-2147024885/0x8007000b)

configuration - 有没有办法在 Windows Store 应用程序的 ApplicationSettings 中存储自己的类的实例?

windows-8 - 如何在 WinRT 中创建点击可移动控件?

c# - 获取当前调用栈

windows-8 - Windows 应用程序认证工具包 - 包全名错误 W8 商店

c# - 在 Windows 8.1 channel 上使用相同的推送通知 channel

c# - VisualStateManager GoToState 不起作用

xaml - Windows Phone 8.1 上使用 MVVM Light 的双向数据绑定(bind)

c# - 如何在 Windows 应用商店应用程序中将内容剪辑为椭圆

html - WinJS:显示软键盘时出现滚动问题