using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Xamarin.Forms; namespace InABox.Mobile { public class IntToColorConverterThreshold { public int Lower { get; set; } public int Upper { get; set; } public Color Color { get; set; } } public class IntToColorConverter: AbstractConverter { public IList Thresholds { get; private set; } public Color DefaultColor { get; set; } public IntToColorConverter() { Thresholds = new ObservableCollection(); } protected override Color Convert(int value, object? parameter = null) { foreach (var threshold in Thresholds.OrderBy(x=>x.Lower)) { if (value >= threshold.Lower && value <= threshold.Upper) return threshold.Color; } return DefaultColor; } } }