Color Conversion with percent Wpf

275 Views Asked by At

I am trying to get brush color from red to green by passing %.I have a datagrid each row has a percentage value. Is there any function like getColor(Red,Green,%) which return the color from red to green a/c to %.

1

There are 1 best solutions below

1
Igor Damiani On

You need to looking for a converter, that is a class that implements IValueConverter interface. You need to work with WPF binding.

public class BackgroundConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Brush someBrush;
        // Put here your logic
        return someBrush;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}