wabbajack/Wabbajack.App/Controls/BrowseItemView.axaml.cs

52 lines
1.9 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.Reactive.Disposables;
using Avalonia.ReactiveUI;
using Material.Icons;
using ReactiveUI;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.Controls;
public partial class BrowseItemView : ReactiveUserControl<BrowseItemViewModel>
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public BrowseItemView()
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
InitializeComponent();
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Title, view => view.Title.Text)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Description, view => view.Description.Text)
.DisposeWith(disposables);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.OneWayBind(ViewModel, vm => vm.Image, view => view.ModListImage.Source)
.DisposeWith(disposables);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.BindCommand(ViewModel, vm => vm.OpenWebsiteCommand, view => view.OpenWebsiteButton)
.DisposeWith(disposables);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.OneWayBind(ViewModel, vm => vm.State, view => view.ExecuteIcon.Kind, s => StateToKind(s));
this.BindCommand(ViewModel, vm => vm.ExecuteCommand, view => view.ExecuteButton)
.DisposeWith(disposables);
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.OneWayBind(ViewModel, vm => vm.Progress, view => view.DownloadProgressBar.Value,
s => s.Value * 1000)
.DisposeWith(disposables);
2021-10-23 16:51:17 +00:00
this.OneWayBind(ViewModel, vm => vm.Tags, view => view.TagsList.Items)
.DisposeWith(disposables);
});
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
private MaterialIconKind StateToKind(ModListState modListState)
{
return modListState switch
2021-09-27 12:42:46 +00:00
{
2021-10-27 21:47:58 +00:00
ModListState.Disabled => MaterialIconKind.Error,
2021-10-23 16:51:17 +00:00
ModListState.Downloaded => MaterialIconKind.PlayArrow,
ModListState.Downloading => MaterialIconKind.LocalAreaNetworkPending,
ModListState.NotDownloaded => MaterialIconKind.Download,
_ => throw new ArgumentOutOfRangeException(nameof(modListState), modListState, null)
};
2021-09-27 12:42:46 +00:00
}
}