我的代码到底有什么问题?
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker FilePicker = new FileOpenPicker();
FilePicker.FileTypeFilter.Add(".exe");
FilePicker.ViewMode = PickerViewMode.List;
FilePicker.SuggestedStartLocation = PickerLocationId.Desktop;
// IF I PUT AWAIT HERE V I GET ANOTHER ERROR¹
StorageFile file = FilePicker.PickSingleFileAsync();
if (file != null)
{
AppPath.Text = file.Name;
}
else
{
AppPath.Text = "";
}
}
它给了我这个错误:
无法将类型“Windows.Foundation.IAsyncOperation”隐式转换为“Windows.Storage.StorageFile”
如果我添加“等待”,就像对代码的评论一样,我会收到以下错误:
¹ 'await' 运算符只能在异步方法中使用。考虑使用“异步”修饰符标记此方法并将其返回类型更改为“任务”。
代码源在这里