我有一个WPF桌面应用程序,我想使用UWP FolderPicker API来选择一个目录。我的应用程序使用UWP打包项目,因此它是作为一个appx构建和运行的。我已经添加了Windows和WindowsBase引用,以及我的项目生成和运行。但是,在尝试使用文件夹选择器时,我遇到了一个运行时错误。我的代码如下:
private async void OnGetDirectory(object parameter)
{
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
// Application now has read/write access to all contents in the picked folder
// (including other sub-folder contents)
Windows.Storage.AccessCache.StorageApplicationPermissions.
FutureAccessList.AddOrReplace("PickedFolderToken", folder);
}
else
{
}
}
我得到的错误是在线系统上。例外情况:
await folderPicker.PickSingleFolderAsync();
错误是
Invalid window handle. (Exception from HRESULT: 0x80070578)'