123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using Avalonia;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Platform.Storage;
- using AvaloniaApplication4.Models;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AvaloniaApplication4.ViewModels
- {
- internal class PersonalPageVM : ViewModelBase
- {
- User _user;
- public User User { get => _user; set => this.RaiseAndSetIfChanged(ref _user, value); }
- public PersonalPageVM(User user)
- {
- User = user;
- }
- public PersonalPageVM()
- {
- User = new User();
- }
- public void ToPageMain()
- {
- MainWindowViewModel.Instance.Uc = new MainPage();
- }
- public async Task AddOnePhoto()
- {
- if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desctop || desctop.MainWindow?.StorageProvider is not { } provider) throw new NullReferenceException("провайдер отсутствует");
- var file = await provider.OpenFilePickerAsync(
- new FilePickerOpenOptions()
- {
- Title = "Выберите изображение",
- AllowMultiple = false,
- FileTypeFilter = [FilePickerFileTypes.All, FilePickerFileTypes.ImageAll]
- }
- );
- if (file != null)
- {
- await using var readStream = await file[0].OpenReadAsync();
- byte[] buffer = new byte[readStream.Length];
- readStream.ReadAtLeast(buffer, 1);
- User.Image = buffer;
- MainWindowViewModel.myConnection.SaveChanges();
- MainWindowViewModel.Instance.Uc = new PesonalPage(_user);
- }
- }
- }
- }
|