using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using Avalonia.Data.Converters; namespace LANCommander.Launcher.Converters; /// /// Multi-value converter that treats the first value as a format string and the /// remaining values as arguments — identical to string.Format(values[0], values[1..]). /// /// XAML usage: /// <MultiBinding Converter="{StaticResource StringFormatConverter}"> /// <Binding Source="{StaticResource GameReadyFormat}" /> <!-- "{0} is ready to play!" --> /// <Binding Path="Title" /> /// </MultiBinding> /// public class StringFormatConverter : IMultiValueConverter { public static readonly StringFormatConverter Instance = new(); public object? Convert(IList values, Type targetType, object? parameter, CultureInfo culture) { if (values.Count == 0 || values[0] is not string format) return null; var args = values.Skip(1).ToArray(); return args.Length == 0 ? format : string.Format(format, args); } }