1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Platform.Storage;
- using CommunityToolkit.Mvvm.Input;
- using Shaker.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace ShakerApp.ViewModels
- {
- internal class LoadConfigViewModel:DisplayViewModelBase<IModel>
- {
- public override string OKContent => "Confirm";
- public override bool CanResize => false;
- public override double Height => 320;
- public override double Width => 620;
- private string selectedFile = string.Empty;
- private LoadConfigViewModel()
- {
- Content = typeof(Views.LoadConfigView);
- }
- static LoadConfigViewModel()
- {
- }
- public string SelectedFile { get => selectedFile; set =>SetProperty(ref selectedFile , value); }
- public override void InitData()
- {
- base.InitData();
- SelectedFile = string.Empty;
- }
- protected override void Save()
- {
- base.Save();
- }
- public ICommand SelectFileCommand => new RelayCommand<string?>(SelectFile);
- private async void SelectFile(string? p)
- {
- if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- var folder = await TopLevel.GetTopLevel(desktop.MainWindow)!.StorageProvider.OpenFilePickerAsync(new Avalonia.Platform.Storage.FilePickerOpenOptions()
- {
- AllowMultiple = false,
- Title = p == null ? "" : App.Current?.FindResource(p) + "",
- FileTypeFilter = new FilePickerFileType[]
- {
- new FilePickerFileType($"{(p ==null ?"": App.Current?.FindResource(p) + "")}"){ Patterns = new []{"*.cfg" } }
- }
- });
- if (folder != null && folder.Count>0)
- {
- SelectedFile = folder.First().Path.LocalPath;
- }
- }
- }
- public static LoadConfigViewModel Instance { get; } = new LoadConfigViewModel();
- }
- }
|