1234567891011121314151617181920212223242526272829303132333435363738 |
- 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<int,Color>
- {
-
- public IList<IntToColorConverterThreshold> Thresholds { get; private set; }
-
- public Color DefaultColor { get; set; }
- public IntToColorConverter()
- {
- Thresholds = new ObservableCollection<IntToColorConverterThreshold>();
- }
-
- 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;
- }
- }
- }
|