I have a problem.
I would like to call my method in xaml (mainWindow) in LinearGradientBrush
--> GradientStop
So I would like to change color in background for an animation. I have a function which has several parameters as :
public static List<Color> GetGradientColors(Color start, Color end, int steps)
{
return GetGradientColors(start, end, steps, 0, steps - 1);
}
public static List<Color> GetGradientColors(Color start, Color end, int steps, int firstStep, int lastStep)
{
var colorList = new List<Color>();
if (steps <= 0 || firstStep < 0 || lastStep > steps - 1)
return colorList;
double aStep = (end.A - start.A) / steps;
double rStep = (end.R - start.R) / steps;
double gStep = (end.G - start.G) / steps;
double bStep = (end.B - start.B) / steps;
for (int i = firstStep; i < lastStep; i++)
{
byte a = (byte)(start.A + (int)(aStep * i));
byte r = (byte)(start.R + (int)(rStep * i));
byte g = (byte)(start.G + (int)(gStep * i));
byte b = (byte)(start.B + (int)(bStep * i));
colorList.Add(Color.FromArgb(a, r, g, b));
}
return colorList;
}
In code XAML :
<LinearGradientBrush StartPoint="0.0, 0.6" EndPoint="1.0, 0.6">
<GradientStop Color="{ Binding GetGradientColors(green, yellow, 2)}" Offset="0"/>
</LinearGradientBrush>
Is it possible to do this?