public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double percentage = (double)value; GradientStop start = GradientStops.First(); GradientStop stop = GradientStops.Last(); foreach (GradientStop gradientStop in GradientStops) { if (start.Offset < gradientStop.Offset && gradientStop.Offset < percentage) { start = gradientStop; } if (percentage < gradientStop.Offset && gradientStop.Offset < stop.Offset) { stop = gradientStop; } } return(new SolidColorBrush(Color.FromScRgb((float)((percentage - stop.Offset) * (start.Color.ScA - stop.Color.ScA) / (start.Offset - stop.Offset) + stop.Color.ScA), (float)((percentage - stop.Offset) * (start.Color.ScR - stop.Color.ScR) / (start.Offset - stop.Offset) + stop.Color.ScR), (float)((percentage - stop.Offset) * (start.Color.ScG - stop.Color.ScG) / (start.Offset - stop.Offset) + stop.Color.ScG), (float)((percentage - stop.Offset) * (start.Color.ScB - stop.Color.ScB) / (start.Offset - stop.Offset) + stop.Color.ScB)))); }
void OnRemoveButtonClicked(object sender, EventArgs e) { if (gradientStops.Count <= 0) { return; } offsets--; gradientStops.Remove(gradientStops.Last()); UpdateOffsets(); UpdateBackground(); }
void OnNewGradientRemoved(object sender, EventArgs e) { if (_gradientStops.Count <= 0) { return; } _offsets--; _gradientStops.Remove(_gradientStops.Last()); UpdateOffsets(_gradientStops, _offsets); UpdateBackground(); }