using System; using System.Globalization; using Avalonia.Data.Converters; using Avalonia.Markup.Xaml; using Avalonia.Media.Imaging; using Nitrox.Launcher.Models.Utils; namespace Nitrox.Launcher.Models.Converters; public sealed class BoolToIconConverter : MarkupExtension, IValueConverter { /// /// String that will be outputted if the input boolean value is true /// public string True { get; set; } /// /// String that will be outputted if the input boolean value is false /// public string False { get; set; } /// /// Decides if the converter will inverse the input boolean value before computing the output /// public bool Invert { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not bool @bool) { return null; } if (Invert) { @bool = !@bool; } return AssetHelper.GetAssetFromStream(@bool ? True : False, static stream => new Bitmap(stream)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); public override object ProvideValue(IServiceProvider serviceProvider) => this; }