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

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

问题描述

我试图让用户使用FileOpenPicker类浏览文件,但是当我在等待状态下使用PickSingleFileAsync函数时,出现以下错误:

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'的定义,并且找不到扩展方法'GetAwaiter'接受类型为'IAsyncOperation'的第一个参数(您是否缺少对'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?

推荐答案

您是否拥有:

using System;

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

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天全站免登陆