我正在编写一个.Net Maui应用程序,它允许用户从他们的目录中 Select 一个文件,显示所选文件的文件路径,然后打开所选文件.问题是,在MacCatalyst上(我在Mac上工作),当文件目录打开供用户 Select 文件时,所有文件都呈灰色显示,无法 Select .以下是单击PickFileButton时的方法:
private async void PickFileButton_Clicked(object sender, EventArgs e)
{
try
{
//var result = await FilePicker.PickAsync();
var result = await FilePicker.PickAsync(new PickOptions
{
FileTypes = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "public.item" } },
{ DevicePlatform.Android, new[] { "*/*" } },
{ DevicePlatform.WinUI, new[] { "*/*" } },
{ DevicePlatform.MacCatalyst, new[] { "*/*" } }
})
});
if (result != null)
{
filePath = result.FullPath;
await FilePathLabel.Dispatcher.DispatchAsync(() =>
{
FilePathLabel.Text = filePath;
});
}
}
catch (Exception ex)
{
// Handle exception if file picker operation fails
Console.WriteLine($"File picking failed: {ex.Message}");
}
}
我已经在Info.plist中将LSSupportsOpeningDocumentsInPlace和应用程序支持iTunes共享设置为真,以防这是导致问题的原因.当我注释掉DevicePlatform.MacCatalyst产品线时,它也不起作用.