我正在寻找适用于Windows 10的触摸屏友好文件选择器.在Windows 8和8.1中,我使用FileOpenPicker:
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.FileTypeFilter.Add(".wma");
fileOpenPicker.FileTypeFilter.Add(".mp3");
fileOpenPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
fileOpenPicker.ViewMode = PickerViewMode.List;
IReadOnlyList<StorageFile> files = await fileOpenPicker.PickMultipleFilesAsync();
Run Code Online (Sandbox Code Playgroud)
这产生了一个很好的界面(例子),但在Windows 10中,相同的代码显示与OpenFileDialog相同的界面(例子),这在触摸屏上很难使用.有谁知道如何在Windows 10中获得Windows 8/8.1样式的FileOpenPicker,或者知道另一种选择?
有没有办法像在 OpenFileDialog 中一样指定过滤器,例如
openFileDialog.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*"
Run Code Online (Sandbox Code Playgroud)
FileOpenpicker.FileTypeFilter.Add似乎不接受相同的语法。MSDN 在这些方面的信息来源很差,并且没有提供 vb.net 的示例
我正在尝试使用 Microsoft.Windows.SDK.Contracts 从 .net 框架 WFP 应用程序访问 Windows10 API。我想使用 FileOpenPicker() 来选择图像以供 Windows.Media.Ocr 进行 OCR 处理。但是我在使用选择器时遇到了“无效的窗口句柄”错误
我发现了一个帖子,它遇到了与 C++/WinRT类似的链接问题。其中一个答案指出“程序会崩溃,因为 FileOpenPicker 在当前线程上寻找一个 CoreWindow 作为对话框的所有者。但我们是一个没有 CoreWindow 的 Win32 桌面应用程序。” 我认为根本原因是一样的。但我不知道如何从基于 .net 框架端的代码中修复。
public async void Load()
{
var picker = new FileOpenPicker()
{
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png", ".bmp" },
};
var file = await picker.PickSingleFileAsync();
if (file != null)
{
}
else
{
}
}
Run Code Online (Sandbox Code Playgroud)
错误消息:System.Exception:'无效的窗口句柄。(来自 HRESULT 的异常:0x80070578)'
我试图使用以下方法选择一个文件:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
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
txt.Text = "Picked file: " + file.Name;
}
else
{
txt.Text = "Operation cancelled.";
}
}
catch (Exception exception)
{
txt.Text = exception.Message;
}
}
Run Code Online (Sandbox Code Playgroud)
...但它抛出一个异常:`不支持指定的方法.";
我复制并粘贴了Windows Phone 8文档中的代码.他们的样本都不起作用.我想也许我错过了一个文档功能/合同或其他什么,但它们甚至不存在于VS for Phone应用程序中.
为什么这不起作用?
我已将其追踪到尝试的第一行:
FileOpenPicker openPicker …Run Code Online (Sandbox Code Playgroud)