-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
65 lines (51 loc) · 1.75 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
namespace PDFImagesHelper;
public partial class MainPage : ContentPage
{
private readonly IFolderPicker _folderPicker;
PickOptions _filePickerOptions;
string _pickedFolder = "";
FileResult _pickedFile;
public MainPage(IFolderPicker folderPicker)
{
InitializeComponent();
_folderPicker = folderPicker;
var customFileType = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "com.adobe.pdf" } }, // UTType values
{ DevicePlatform.WinUI, new[] { ".pdf" } }, // file extension
{ DevicePlatform.macOS, new[] { "com.adobe.pdf" } }, // UTType values
});
_filePickerOptions = new()
{
PickerTitle = "Seleziona un pdf",
FileTypes = customFileType,
};
}
private async void ChooseDirectory(object sender, EventArgs e)
{
var pickedFolder = await _folderPicker.PickFolder();
DirectoryLabel.Text = _pickedFolder = pickedFolder;
SemanticScreenReader.Announce(DirectoryLabel.Text);
}
private async void ChooseFile(object sender, EventArgs e)
{
var pickedFile = await PickFile(_filePickerOptions);
_pickedFile = pickedFile;
FileLabel.Text = pickedFile.FullPath;
SemanticScreenReader.Announce(FileLabel.Text);
}
public async Task<FileResult> PickFile(PickOptions options)
{
try
{
var result = await FilePicker.Default.PickAsync(options);
return result;
}
catch (Exception ex)
{
// The user canceled or something went wrong
}
return null;
}
}