wabbajack/Wabbajack.App/ViewModels/SubViewModels/SlideViewModel.cs

37 lines
897 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Avalonia.Media;
using Avalonia.Media.Imaging;
2021-10-21 03:18:15 +00:00
using Avalonia.Threading;
2021-09-27 12:42:46 +00:00
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.DTOs.DownloadStates;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.ViewModels.SubViewModels;
public class SlideViewModel : ViewModelBase
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public SlideViewModel()
{
Activator = new ViewModelActivator();
Image = null;
}
[Reactive] public IMetaState MetaState { get; set; }
[Reactive] public IImage? Image { get; set; }
public bool Loading { get; set; }
public async Task PreCache(HttpClient client)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
Loading = true;
var url = await client.GetByteArrayAsync(MetaState.ImageURL);
var img = new Bitmap(new MemoryStream(url));
await Dispatcher.UIThread.InvokeAsync(() => { Image = img; });
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
Loading = false;
2021-09-27 12:42:46 +00:00
}
}