I have a list of objects with a Color property. The List may have any number of items ranging from 10 to 4000. I want the Color property of first item to be green and the last item to be red. And all the in between items should get the colors in between red and green (gradient) based on their position (earliest more green and later more red. The following code works only if the list count is less than 255. It returns all white color if the list size exceeds 255
Color start = Colors.White;
Color end = Colors.Green;
int steps = lstTag.Count;
int stepA = ((end.A - start.A) / (steps - 1));
int stepR = ((end.R - start.R) / (steps - 1));
int stepG = ((end.G - start.G) / (steps - 1));
int stepB = ((end.B - start.B) / (steps - 1));
int i = 0;
foreach (ArgsData data in lstTag)
{
var a = byte.Parse((start.A + (stepA * i)).ToString());
var r = byte.Parse((start.R + (stepR * i)).ToString());
var g = byte.Parse((start.G + (stepG * i)).ToString());
var b = byte.Parse((start.B + (stepB * i)).ToString());
data.ColorCode = new SolidColorBrush(Color.FromArgb(a, r, g, b));
i++;
}
Any help will be highly appreciated.