设置文件夹打开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/