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

44 lines
1.0 KiB
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;
namespace Wabbajack.App.ViewModels.SubViewModels
{
public class SlideViewModel : ViewModelBase
{
[Reactive]
public IMetaState MetaState { get; set; }
[Reactive]
public IImage? Image { get; set; }
public bool Loading { get; set; } = false;
public SlideViewModel()
{
Activator = new ViewModelActivator();
Image = null;
}
public async Task PreCache(HttpClient client)
{
Loading = true;
var url = await client.GetByteArrayAsync(MetaState.ImageURL);
2021-10-21 03:18:15 +00:00
var img = new Bitmap(new MemoryStream(url));
await Dispatcher.UIThread.InvokeAsync(() =>
{
Image = img;
});
2021-09-27 12:42:46 +00:00
Loading = false;
}
}
}