【发布时间】:2021-05-22 16:53:19
【问题描述】:
我将 MRTK 用于 hololens 应用程序,我需要选择用户放入其文档文件夹中的文件。我正在尝试访问 FileOpenPicker 并通过按下按钮使用 PickSingleFileAsync() 函数来获取文件,然后将其加载到我的应用程序中。
这个函数里面的代码基本上就是我在做的:
private async void PickAFileButton_Click(object sender, RoutedEventArgs e)
{
// Clear previous returned file name, if it exists, between iterations of this scenario
OutputTextBlock.Text = "";
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
OutputTextBlock.Text = "Picked photo: " + file.Name;
}
else
{
OutputTextBlock.Text = "Operation cancelled.";
}
}
但是,当我构建并部署到 Hololens Emulator 时,当我按下按钮时,它会很好地运行代码的第一部分,但在这一行出现异常
StorageFile file = await openPicker.PickSingleFileAsync();
经过广泛的研究和一些挫折后,我发了一个非常糟糕和模糊的帖子here。
在那篇文章中,我引用了 2 年前制作的 post,并说你不能这样做,但 The Microsoft docs for Hololens 说你可以使用文件选择器,在这种情况下是 FileOpenPicker。
我发现 this 帖子埋在 Windows Mixed Reality 开发者论坛中,这是相关的,但不是我遇到的问题,我仍然觉得有必要将其包含在这篇帖子中。
我还想补充一点,我确实安装了文件选择器应用程序。根据this post on Microsoft Docs,如果您调用 FileOpenPicker,它将打开您设备上首次安装的任何文件选择器。
此外,在 MRTK 和正在生成的 Appx 中,我确保启用“PictureLibrary”功能的权限。
任何帮助都将不胜感激,我觉得我等了太久才就这个主题发表更正式的帖子,我希望能得到一些答案。谢谢!
【问题讨论】:
标签: c# unity3d hololens mrtk fileopenpicker