using System.Reactive; using ReactiveUI; using System.Collections.Generic; using System.Diagnostics; using DesertPaintCodex.Services; namespace DesertPaintCodex.ViewModels { public class SelectProfileViewModel : ViewModelBase { public List Profiles { get; private set; } private string? _selectedItem; public string? SelectedItem { get => _selectedItem; set => this.RaiseAndSetIfChanged(ref _selectedItem, value); } public SelectProfileViewModel() { Profiles = ProfileManager.GetProfileList(); var okEnabled = this.WhenAnyValue( x => x.SelectedItem, x => !string.IsNullOrWhiteSpace(x)); NewProfile = ReactiveCommand.Create(() => { }); Ok = ReactiveCommand.Create(() => { Debug.Assert(_selectedItem != null); ProfileManager.LoadProfile(_selectedItem); }, okEnabled); Cancel = ReactiveCommand.Create(() => { }); if (Profiles.Count > 0) { SelectedItem = Profiles[0]; } } public ReactiveCommand NewProfile { get; } public ReactiveCommand Ok { get; } public ReactiveCommand Cancel { get; } } }