using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Platform.Storage; using Avalonia.ReactiveUI; using Presence.Desktop.ViewModels; using ReactiveUI; using System; using System.Linq; using System.Reactive; using System.Threading.Tasks; namespace Presence.Desktop.Views { public partial class MainWindow : ReactiveWindow { public MainWindow() { InitializeComponent(); this.WhenActivated(action => { action(ViewModel.ShowOpenFileDialog.RegisterHandler(ShowOpenFileDialogAsync)); }); } public static FilePickerFileType FileCsv { get; } = new("Comma-Separated Values") { Patterns = ["*.csv"], AppleUniformTypeIdentifiers = ["public.comma-separated-values-text"], MimeTypes = ["application/vnd.ms-excel", "text/csv"] }; private async Task ShowOpenFileDialogAsync(InteractionContext interaction) { var topLevel = GetTopLevel(this); FilePickerOpenOptions fpOptions = new FilePickerOpenOptions { AllowMultiple = false, Title = "students csv", FileTypeFilter = [FileCsv] }; var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(fpOptions); interaction.SetOutput(storageFile.First().Path.ToString()); } } }