我已为文件夹选取器引用此Folder Picker .NET MAUI链接。但我无法在文件夹选取器中指定特定的文件类型。
就像如果我指定类型为.txt,那么它应该只显示包含**.txt**文件的文件夹同样。
public async Task<string> PickFolder()
{
var folderPicker = new WindowsFolderPicker();
// Might be needed to make it work on Windows 10
folderPicker.FileTypeFilter.Add(".txt");
// Get the current window's HWND by passing in the Window object
var hwnd = ((MauiWinUIWindow)App.Current.Windows[0].Handler.PlatformView).WindowHandle;
// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(folderPicker, hwnd);
var result = await folderPicker.PickSingleFolderAsync();
return result?.Path;
}
1条答案
按热度按时间4ioopgfo1#
我已经使用了文件夹选择器和给定的条件,检查扩展名,它是工作的方式,我想要的。