presence/Presence.Desktop/Views/MainWindow.axaml.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2024-12-10 05:26:38 +00:00
using Avalonia.Controls;
2024-12-10 17:47:49 +00:00
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;
2024-12-10 05:26:38 +00:00
namespace Presence.Desktop.Views
{
2024-12-10 17:47:49 +00:00
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
2024-12-10 05:26:38 +00:00
{
public MainWindow()
{
InitializeComponent();
2024-12-10 17:47:49 +00:00
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<Unit, string?> 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());
2024-12-10 05:26:38 +00:00
}
2024-12-10 17:47:49 +00:00
2024-12-10 05:26:38 +00:00
}
}