UWP 应用:FileOpenPicker PickSingleFileAsync() 不能等待 [英] UWP app: FileOpenPicker PickSingleFileAsync() can't await

查看:15
本文介绍了UWP 应用:FileOpenPicker PickSingleFileAsync() 不能等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户使用 FileOpenPicker 类浏览文件,但是当我将 PickSingleFileAsync 函数与 await 一起使用时,出现以下错误:

I'm trying to let the user browse for a file with the FileOpenPicker class, but when I use the PickSingleFileAsync function with await, I get following error:

IAsyncOperation"不包含GetAwaiter"的定义,并且找不到接受IAsyncOperation"类型的第一个参数的扩展方法GetAwaiter"(您是否缺少System"的 using 指令?)

'IAsyncOperation' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation' could be found (are you missing a using directive for 'System'?)

这是在最后一行给出错误的函数:

This is the function that gives the error on it's last line:

private async void browseFileButton_Click(object sender, RoutedEventArgs e) {
    FileOpenPicker filePicker = new FileOpenPicker();
    filePicker.ViewMode = PickerViewMode.Thumbnail;

    selectedFile = await filePicker.PickSingleFileAsync();
}

来自 Microsoft 的文档包含一个以相同方式使用 FileOpenPicker 的示例.有没有人遇到过这个问题,或者有没有人解决这个问题?

The documentation from Microsoft contains an example that uses the FileOpenPicker in the same way. Has anybody had this problem or has anybody a solution for this problem?

推荐答案

你有吗:

使用系统;

在类文件的顶部?我只是尝试将您的示例添加到项目中,并在删除此引用时重复了您的错误...

at the top of the class file? I just tried adding your sample to a project and duplicated your error when I removed this reference...

这篇关于UWP 应用:FileOpenPicker PickSingleFileAsync() 不能等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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