wabbajack/Wabbajack.App/Controls/BrowseItemView.axaml.cs
2021-10-27 15:47:58 -06:00

52 lines
1.9 KiB
C#

using System;
using System.Reactive.Disposables;
using Avalonia.ReactiveUI;
using Material.Icons;
using ReactiveUI;
namespace Wabbajack.App.Controls;
public partial class BrowseItemView : ReactiveUserControl<BrowseItemViewModel>
{
public BrowseItemView()
{
InitializeComponent();
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);
this.OneWayBind(ViewModel, vm => vm.Image, view => view.ModListImage.Source)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.OpenWebsiteCommand, view => view.OpenWebsiteButton)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.State, view => view.ExecuteIcon.Kind, s => StateToKind(s));
this.BindCommand(ViewModel, vm => vm.ExecuteCommand, view => view.ExecuteButton)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Progress, view => view.DownloadProgressBar.Value,
s => s.Value * 1000)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Tags, view => view.TagsList.Items)
.DisposeWith(disposables);
});
}
private MaterialIconKind StateToKind(ModListState modListState)
{
return modListState switch
{
ModListState.Disabled => MaterialIconKind.Error,
ModListState.Downloaded => MaterialIconKind.PlayArrow,
ModListState.Downloading => MaterialIconKind.LocalAreaNetworkPending,
ModListState.NotDownloaded => MaterialIconKind.Download,
_ => throw new ArgumentOutOfRangeException(nameof(modListState), modListState, null)
};
}
}