A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
1011 B

using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
using Avalonia.Media.Immutable;
namespace ControlCatalog.Converter;
public sealed class GdpToBrushConverter : IValueConverter
{
private readonly ImmutableSolidColorBrush _orangeBrush = new(Colors.Orange, 0.6);
private readonly ImmutableSolidColorBrush _yellowBrush = new(Colors.Yellow, 0.6);
private readonly ImmutableSolidColorBrush _greenBrush = new(Colors.LightGreen, 0.6);
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not int gdp)
return AvaloniaProperty.UnsetValue;
return gdp switch
{
<= 5000 => _orangeBrush,
<= 10000 => _yellowBrush,
_ => _greenBrush
};
}
object IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}