presence_new/Presence.Desktop/Views/GroupView.axaml.cs
2024-12-21 14:14:33 +03:00

46 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Platform.Storage;
using Avalonia.ReactiveUI;
using Presence.Desktop.ViewModels;
using ReactiveUI;
namespace Presence.Desktop.Views
{
public partial class GroupView : ReactiveUserControl<GroupViewModel>
{
public GroupView()
{
this.WhenActivated(action =>
{
action(ViewModel!.SelectFileInteraction.RegisterHandler(ShowFileDialog));
});
AvaloniaXamlLoader.Load(this);
}
private async Task ShowFileDialog(IInteractionContext<string?, string?> context)
{
var topLevel = TopLevel.GetTopLevel(this);
var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(
new FilePickerOpenOptions()
{
AllowMultiple = false,
Title = context.Input
}
);
if (storageFile.Count > 0)
{
context.SetOutput(storageFile.First().Path.ToString());
}
else
{
// Обработка случая, когда выбор файла отменен
// Например, можно вывести сообщение или просто ничего не делать
}
}
}
}