c# - 建议的开始位置与实际开始位置

标签 c# uwp filepicker

设置文件夹打开FileOpenPicker时,UWP中没有ActualStartLocation之类的东西,这就是我提出问题的原因。有一个 SuggestedStartLocation,但是 Microsoft site明确指出:

“SuggestedStartLocation 并不总是用作文件选取器的起始位置。为了给用户一种一致性的感觉,文件选取器会记住用户导航到的最后一个位置,并且通常会从该位置开始”

SuggestedStartLocation 会记住您所在的位置,并且每次都会继续打开同一个文件夹。例如,将此代码添加到 UWP 项目中的按钮单击事件:

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null) {
    TextBlock1.Text = "Selected Photo: " + file.Name;
} else {
    TextBlock1.Text = "Operation cancelled.";
}

现在运行程序并选择一张图片。

关闭程序更改代码以使用 MusicLibrary 而不是 PicturesLibrary。

再次运行该程序,当您单击该按钮时,您将返回图片库,即使您要求查看音乐也是如此。

有没有办法覆盖它并强制文件选择器将开始的位置? (即:ActualStartLocation)

我正在尝试制作一个应用程序,用户可以在其中选择图片和音乐文件,如果图片选择器始终在图片文件夹中打开并且音乐选择器始终在音乐文件夹中打开,那就太好了。

最佳答案

如您所知,这是设计使然。

"The SuggestedStartLocation is not always used as the start location for the file picker. To give the user a sense of consistency, the file picker remembers the last location that the user navigated to and will generally start at that location."

当您使用 FileOpenPicker 选择文件时,PickerHost.exe 将启动。 PickerHost 是一个系统应用程序。并且它会记录你最近访问过的位置。您无法更改申请中的记录。目前,没有这样的“ActualStartLocation”属性来实现你想要的。如果您确实需要此功能,欢迎您在 UserVoice 上提问.

关于c# - 建议的开始位置与实际开始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43438573/

相关文章:

c# - this.RaisePropertyChanged ("")是什么意思?

c# - 是否可以访问自动实现的属性背后的支持字段?

c# - UWP AudioGraph 设置不适用于所有设备,HRESULT : 0x88960001 thrown on AddOutgoingConnection

java - 在 native Android 文件选择器中按 mime 类型或扩展名过滤

ios - 如何使用 cordova 从 iOS 设备中的 iCloud 读取文件?

c# - 从 USB-GPS-Receiver 读取数据

c# - C#OpenCV:检测 parking 标志

c# - 通用应用程序的快捷方式

windows - 如何从 SoftwareBitmap (UWP) 中正确释放 BitmapBuffer?

javascript - 适用于 Evernote 和 OneDrive 的文件选择器 API