FileSavePicker 和弃用的 ApplicationViewState [英] FileSavePicker and deprecated ApplicationViewState

查看:22
本文介绍了FileSavePicker 和弃用的 ApplicationViewState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileSavePicker 的文档中,它指出:

In the documentation for the FileSavePicker, it states:

警告如果您在应用程序被捕捉时尝试显示文件选择器,则文件选择器将不会显示并且会引发异常.您可以通过确保您的应用程序没有被捕捉或在调用文件选择器之前取消捕捉来避免这种情况.

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,所以我不能只是尝试然后退回到其他东西.我也不想强制应用程序取消对齐.

I'm currently checking to see if the app is snapped or not, and my app responds differently in each case. My default behavior isn't showing the FileSavePicker, either, so I can't just try and then fall back to something else. Nor do I want to force the app to unsnap.

但是,ApplicationViewState 在 8.1 之后被弃用.在该文档和相关搜索中,建议开发人员直接访问窗口大小以确定正确的行为.但是,如果视图状态不再可用,我怎么知道文件选择器是否会抛出异常?应用在多大尺寸时被视为对齐"?

However, ApplicationViewState is deprecated post-8.1. In that documentation and related searching, developers are advised to access the window size directly in order to determine proper behavior. However, if the view state is no longer available, how do I know if the file picker will throw an exception or not? At what size is the app considered 'snapped'?

另外,我使用的是 C++,所以与 C++ 兼容的答案会很棒.我也不介意看到 C# 解决方案.

Also, I'm using C++, so an answer compatible with C++ would be splendid. I wouldn't mind seeing the C# solution, too.

推荐答案

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

In regards to the FileSavePicker documentation - I believe that it is just an oversight. The text you quote was from the Windows 8 version, and to me it looks like it didn't get updated for Windows 8.1.

如果您查看 FileOpenPicker文档,您会看到它已更新:

If you look at the FileOpenPicker documentation, you see that it was updated:

重要提示 在 Windows 8 中,如果您尝试在捕捉应用程序时显示文件选择器,将不会显示文件选择器并会引发异常.您可以通过确保您的应用程序未被捕捉或在调用文件选择器之前取消捕捉来避免这种情况....请注意,Windows 8.1 没有定义特定的捕捉窗口大小.取而代之的是,用户可以将应用程序调整为任何宽度,最小化.因此,如果您的应用仅在 Windows 8.1 上部署,您可以忽略该主题的示例代码中的 EnsureUnsnapped 函数并调用它.

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 下运行,您可以忽略状态并安全地打开文件对话框.

The last sentence (in bold) above essentially says that you can ignore state and safely open the file dialogs if you are running under Windows 8.1.

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

To test the above, I used VS 2012 to create a Windows 8 application with a file save picker (in C#). I believe the outcome will be the same with C++, but I am not 100% certain.

我应该注意,我的测试应用程序不会检查视图状态,而是总是尝试打开文件对话框.

I should note that my test application does not check for view state and always tries to open a file dialog.

当应用程序在 Windows 8 下以 snapped 状态运行时,应用程序会导致错误.在 Windows 8.1 下运行时,相同的应用程序(相同的二进制文件)允许打开文件保存对话框而不会出现问题.如前所述,Windows 8.1 中没有对齐状态,因此我测试应用程序的方式是将应用程序打开到最小宽度(320 像素).

When the application is run under Windows 8 in the snapped state, the application causes an error. That same application (same binary) when run under Windows 8.1 allows the file save dialog to open without issue. As mentioned previously there is no snapped state in Windows 8.1, so the way I tested the application was to open the application to the minimum width (320 pixels).

总结:

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

这篇关于FileSavePicker 和弃用的 ApplicationViewState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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